dsh-workflow-canvas 0.2.1 → 0.2.4

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
@@ -169,6 +169,9 @@ window.__ModuleLoader__.load({
169
169
  exportFail: '复制失败(剪贴板不可用)',
170
170
  autoLayoutBtn: '⊞ 自动排版',
171
171
  layoutDone: '已自动整理布局',
172
+ clearCanvasBtn: '✕ 清空画布',
173
+ newBlankCanvas: '+ 新建空白画布',
174
+ clearedCanvas: '已清空画布(可用 ↶ 撤销)',
172
175
  cycleBlocked: '不能形成环,已阻止连线',
173
176
  builtinTemplates: '内置示例模板',
174
177
  myPresets: '我的预设',
@@ -180,6 +183,9 @@ window.__ModuleLoader__.load({
180
183
  fxStandard: '标准',
181
184
  fxVivid: '炫酷',
182
185
  tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
186
+ stDeadEnd: '无出边',
187
+ tipDeadEnd: '该子代理节点没有下游连线:若需把产出交给后续节点或终审 Lead,请从右侧端口连出',
188
+ singleModelHint: '当前仅 1 个可用模型,暂无其它备用路由',
183
189
  importNone: '剪贴板里没有可识别的画布数据',
184
190
  importBad: '画布数据格式不对',
185
191
  tipSync: '把当前画布同步给 Host(会在对话里留一条同步记录)',
@@ -264,6 +270,9 @@ window.__ModuleLoader__.load({
264
270
  exportFail: 'Copy failed (clipboard unavailable)',
265
271
  autoLayoutBtn: '⊞ Auto layout',
266
272
  layoutDone: 'Layout tidied',
273
+ clearCanvasBtn: '✕ Clear canvas',
274
+ newBlankCanvas: '+ New blank canvas',
275
+ clearedCanvas: 'Canvas cleared (use Undo to restore)',
267
276
  cycleBlocked: 'Cannot create a cycle',
268
277
  builtinTemplates: 'Starter templates',
269
278
  myPresets: 'Saved presets',
@@ -275,6 +284,9 @@ window.__ModuleLoader__.load({
275
284
  fxStandard: 'Standard',
276
285
  fxVivid: 'Vivid',
277
286
  tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
287
+ stDeadEnd: 'No out-link',
288
+ tipDeadEnd: 'This subagent has no outgoing link: wire it to a downstream node or Lead so its output is consumed',
289
+ singleModelHint: 'Only 1 model available — no alternate fallback route',
278
290
  importNone: 'No canvas data found in the clipboard',
279
291
  importBad: 'Canvas data is malformed',
280
292
  tipSync: 'Publish this canvas to the host (leaves one sync record in the chat)',
@@ -474,6 +486,13 @@ window.__ModuleLoader__.load({
474
486
  color: C.dim, pointerEvents: 'none', zIndex: 3, whiteSpace: 'nowrap',
475
487
  display: 'inline-flex', alignItems: 'center', gap: '3px',
476
488
  },
489
+ warnChip: {
490
+ position: 'absolute', left: '12px', bottom: '4px', fontSize: '9px', lineHeight: '13px',
491
+ padding: '1px 5px', borderRadius: '999px',
492
+ color: '#d29922', background: 'rgba(210,153,34,0.14)', border: '1px solid rgba(210,153,34,0.55)',
493
+ pointerEvents: 'auto', zIndex: 5, whiteSpace: 'nowrap',
494
+ display: 'inline-flex', alignItems: 'center', gap: '2px',
495
+ },
477
496
  statusBtn: {
478
497
  position: 'absolute', right: '12px', bottom: '3px', fontSize: '10px', lineHeight: '14px',
479
498
  padding: '1px 6px', borderRadius: '999px', border: '1px solid ' + C.border,
@@ -822,6 +841,43 @@ window.__ModuleLoader__.load({
822
841
  return set;
823
842
  }
824
843
 
844
+ /**
845
+ * Reachable agent nodes with zero outgoing edges when the graph has at least
846
+ * one reachable non-entry Lead that is NOT an ancestor of that agent (so the
847
+ * agent likely forgot to wire into a downstream or terminal Lead).
848
+ */
849
+ function deadEndNodeIds(nodes, edges) {
850
+ const list = Array.isArray(nodes) ? nodes : [];
851
+ const linkList = Array.isArray(edges) ? edges : [];
852
+ const reachable = reachableFrom(list, linkList);
853
+ const downstreamLeads = list.filter((n) => n.kind === 'lead' && n.id !== 'lead' && reachable.has(n.id));
854
+ if (!downstreamLeads.length) return new Set();
855
+ const hasOut = new Set(linkList.map((e) => e.from));
856
+ const parents = new Map();
857
+ for (const e of linkList) {
858
+ if (!parents.has(e.to)) parents.set(e.to, []);
859
+ parents.get(e.to).push(e.from);
860
+ }
861
+ const ancestorsOf = (id) => {
862
+ const seen = new Set();
863
+ const stack = [id];
864
+ while (stack.length) {
865
+ const cur = stack.pop();
866
+ for (const p of parents.get(cur) || []) {
867
+ if (!seen.has(p)) { seen.add(p); stack.push(p); }
868
+ }
869
+ }
870
+ return seen;
871
+ };
872
+ const out = new Set();
873
+ for (const n of list) {
874
+ if (n.kind === 'lead' || !reachable.has(n.id) || hasOut.has(n.id)) continue;
875
+ const anc = ancestorsOf(n.id);
876
+ if (downstreamLeads.some((ln) => !anc.has(ln.id))) out.add(n.id);
877
+ }
878
+ return out;
879
+ }
880
+
825
881
  /** True when adding `fromId -> toId` would create a cycle or point into entry Lead. */
826
882
  function wouldCycle(nodes, edges, fromId, toId) {
827
883
  if (!fromId || !toId || fromId === toId || toId === 'lead') return true;
@@ -1009,6 +1065,7 @@ window.__ModuleLoader__.load({
1009
1065
  { id: 'n_b', kind: 'agent', label: en ? 'Option B (Bold)' : '方案 B(创新)', provider: '', model: '', reasoning: '', preset: 'minimal', keepSession: false, role: en ? 'Propose a high-leverage alternative with better long-term payoff.' : '提出上限更高、长期收益更大的进阶方案。' },
1010
1066
  { id: 'n_pick', kind: 'lead', label: en ? 'Lead Pick' : 'Lead 拍板', provider: '', model: '', role: en ? 'Compare both options and pick the direction to execute.' : '对比两份方案,选定最终路线并补充约束。' },
1011
1067
  { id: 'n_exec', kind: 'agent', label: en ? 'Execute' : '执行落地', provider: '', model: '', reasoning: '', preset: 'standard', keepSession: false, role: en ? 'Deliver the chosen solution end to end.' : '按照拍板路线完成最终交付。' },
1068
+ { id: 'n_review', kind: 'lead', label: en ? 'Lead Review' : 'Lead 验收', provider: '', model: '', role: en ? 'Verify the deliverable matches the chosen direction and sign off.' : '核对最终产出是否符合拍板方向,确认无误后交付。' },
1012
1069
  ];
1013
1070
  const abEdges = [
1014
1071
  { id: 'a1', from: 'lead', to: 'n_a', type: 'prompt' },
@@ -1016,6 +1073,7 @@ window.__ModuleLoader__.load({
1016
1073
  { id: 'a3', from: 'n_a', to: 'n_pick', type: 'prompt' },
1017
1074
  { id: 'a4', from: 'n_b', to: 'n_pick', type: 'prompt' },
1018
1075
  { id: 'a5', from: 'n_pick', to: 'n_exec', type: 'prompt' },
1076
+ { id: 'a6', from: 'n_exec', to: 'n_review', type: 'prompt' },
1019
1077
  ];
1020
1078
  return [
1021
1079
  {
@@ -1032,7 +1090,7 @@ window.__ModuleLoader__.load({
1032
1090
  },
1033
1091
  {
1034
1092
  id: 'tpl-ab',
1035
- name: en ? 'Parallel Options → Decide → Execute' : '并行方案对比 → 拍板 → 执行',
1093
+ name: en ? 'Parallel Options → Decide → Execute → Review' : '并行方案对比 → 拍板 → 执行 → 验收',
1036
1094
  nodes: layoutGraph(abNodes, abEdges),
1037
1095
  edges: abEdges,
1038
1096
  },
@@ -1305,6 +1363,8 @@ window.__ModuleLoader__.load({
1305
1363
  edgesRef.current = edges;
1306
1364
  const selectedIdsRef = useRef(selectedIds);
1307
1365
  selectedIdsRef.current = selectedIds;
1366
+ const skipDirtyOnce = useRef(false);
1367
+ const staleChildIds = useRef(new Set());
1308
1368
 
1309
1369
  useEffect(() => {
1310
1370
  const stamp = applyStamp.current;
@@ -1312,8 +1372,13 @@ window.__ModuleLoader__.load({
1312
1372
  saveDoc(sessionId, { nodes, edges, enabled }, stamp === null ? undefined : stamp);
1313
1373
  }, [sessionId, nodes, edges, enabled]);
1314
1374
 
1315
- // Any structural edit after enabling leaves the Host copy stale.
1375
+ // Any structural edit after enabling leaves the Host copy stale,
1376
+ // except when the update came directly from the Host itself.
1316
1377
  useEffect(() => {
1378
+ if (skipDirtyOnce.current) {
1379
+ skipDirtyOnce.current = false;
1380
+ return;
1381
+ }
1317
1382
  if (enabled) setDirty(true);
1318
1383
  }, [nodes, edges]);
1319
1384
 
@@ -1356,12 +1421,15 @@ window.__ModuleLoader__.load({
1356
1421
  }, [openModelFor]);
1357
1422
 
1358
1423
  // Publishing costs one visible command row in the conversation, so it only
1359
- // happens when the user enables the canvas or asks for it explicitly.
1360
- const pushPlan = (nextEnabled) => {
1424
+ // happens when the user enables the canvas, loads a preset/import, clears,
1425
+ // or asks for it explicitly.
1426
+ const pushPlan = (nextEnabled, overrideNodes, overrideEdges) => {
1361
1427
  try {
1362
1428
  const face = sessionFace(sessionId);
1363
1429
  if (!face || typeof face.command !== 'function') { flash(t('syncFailed')); return; }
1364
- const res = buildPlan(nodes, edges);
1430
+ const curNodes = Array.isArray(overrideNodes) ? overrideNodes : nodesRef.current;
1431
+ const curEdges = Array.isArray(overrideEdges) ? overrideEdges : edgesRef.current;
1432
+ const res = buildPlan(curNodes, curEdges);
1365
1433
  const payload = res.error
1366
1434
  ? { enabled: nextEnabled, error: res.error }
1367
1435
  : { enabled: nextEnabled, plan: res.plan };
@@ -1372,7 +1440,7 @@ window.__ModuleLoader__.load({
1372
1440
  if (ack && ack.ok) {
1373
1441
  lastSync.current = sig;
1374
1442
  setDirty(false);
1375
- setStatusById({});
1443
+ snapshotStaleCatalog();
1376
1444
  flash(t('syncedToHost'));
1377
1445
  } else {
1378
1446
  flash(t('syncFailed'));
@@ -1418,6 +1486,26 @@ window.__ModuleLoader__.load({
1418
1486
 
1419
1487
  const NODE_MARK = /#([^\s#]+)$/;
1420
1488
 
1489
+ /** Mark existing historical subagent sessions as stale before a fresh run. */
1490
+ const snapshotStaleCatalog = () => {
1491
+ try {
1492
+ const sessions = hostCtx && hostCtx.sessions;
1493
+ if (sessions && sessionId) {
1494
+ const state = sessions.list.getSnapshot();
1495
+ const proj = state && state.projectionsBySession && state.projectionsBySession[sessionId];
1496
+ const catalog = proj && proj.values && proj.values.subagentCatalog;
1497
+ if (Array.isArray(catalog)) {
1498
+ const stale = new Set();
1499
+ for (const entry of catalog) {
1500
+ if (entry && entry.id) stale.add(entry.id);
1501
+ }
1502
+ staleChildIds.current = stale;
1503
+ }
1504
+ }
1505
+ } catch (_e) { /* ignore */ }
1506
+ setStatusById({});
1507
+ };
1508
+
1421
1509
  const readCatalog = () => {
1422
1510
  try {
1423
1511
  const sessions = hostCtx && hostCtx.sessions;
@@ -1437,9 +1525,6 @@ window.__ModuleLoader__.load({
1437
1525
  const child = state.byId && state.byId[entry.id];
1438
1526
  const timingProj = state.projectionsBySession && state.projectionsBySession[entry.id];
1439
1527
  const timing = timingProj && timingProj.values && timingProj.values.subagentTiming;
1440
- if (child && child.running) nextStatus[nodeId] = 'running';
1441
- else if (timing && timing.lastTurnCompleted === false) nextStatus[nodeId] = 'failed';
1442
- else nextStatus[nodeId] = 'done';
1443
1528
  if (entry.id) {
1444
1529
  const prev = nextRuns[nodeId];
1445
1530
  nextRuns[nodeId] = {
@@ -1449,6 +1534,13 @@ window.__ModuleLoader__.load({
1449
1534
  count: prev ? prev.count + 1 : 1,
1450
1535
  };
1451
1536
  }
1537
+ if (child && child.running) {
1538
+ if (entry.id) staleChildIds.current.delete(entry.id);
1539
+ nextStatus[nodeId] = 'running';
1540
+ } else if (!entry.id || !staleChildIds.current.has(entry.id)) {
1541
+ if (timing && timing.lastTurnCompleted === false) nextStatus[nodeId] = 'failed';
1542
+ else nextStatus[nodeId] = 'done';
1543
+ }
1452
1544
  }
1453
1545
  return { status: nextStatus, runs: nextRuns };
1454
1546
  } catch (_e) {
@@ -1460,6 +1552,7 @@ window.__ModuleLoader__.load({
1460
1552
  // catalog lists children by `label#nodeId`. Lead steps run inside the
1461
1553
  // conversation, so the canvas cannot observe them and must not pretend to.
1462
1554
  useEffect(() => {
1555
+ staleChildIds.current = new Set();
1463
1556
  const sessions = hostCtx && hostCtx.sessions;
1464
1557
  const face = sessionFace(sessionId);
1465
1558
  if (!sessions || !sessionId || !face || typeof face.subscribe !== 'function') return undefined;
@@ -1477,8 +1570,6 @@ window.__ModuleLoader__.load({
1477
1570
  const onSnapshot = () => {
1478
1571
  let running = false;
1479
1572
  try { running = Boolean(face.getSnapshot().running); } catch (_e) { running = false; }
1480
- // A new turn means a new run: drop the previous run's statuses first.
1481
- if (running && !wasRunning) setStatusById({});
1482
1573
  const finished = !running && wasRunning;
1483
1574
  wasRunning = running;
1484
1575
  if (running && !timer) { read(); timer = setInterval(read, 700); }
@@ -1813,6 +1904,28 @@ window.__ModuleLoader__.load({
1813
1904
  flash(t('layoutDone'));
1814
1905
  };
1815
1906
 
1907
+ const clearCanvas = () => {
1908
+ const blank = [{ id: 'lead', kind: 'lead', x: 40, y: 203, label: 'Lead', task: '', provider: '', model: '', role: '' }];
1909
+ pushSnapshot();
1910
+ if (enabled) {
1911
+ skipDirtyOnce.current = true;
1912
+ setEnabled(false);
1913
+ setDirty(false);
1914
+ pushPlan(false, blank, []);
1915
+ }
1916
+ setNodes(blank);
1917
+ setEdges([]);
1918
+ setSelectedIds([]);
1919
+ setRoleEditFor(null);
1920
+ setOpenModelFor(null);
1921
+ setPresetOpen(null);
1922
+ setMenuOpen(false);
1923
+ snapshotStaleCatalog();
1924
+ setRunsById({});
1925
+ setTimeout(() => centerOn(40 + NODE_W / 2, 203 + NODE_H / 2, 1), 0);
1926
+ flash(t('clearedCanvas'));
1927
+ };
1928
+
1816
1929
  const exportToClipboard = () => {
1817
1930
  const cleanNodes = nodesRef.current.map((n) => {
1818
1931
  const { runs: _runs, ...rest } = n;
@@ -2256,13 +2369,20 @@ window.__ModuleLoader__.load({
2256
2369
  };
2257
2370
 
2258
2371
  /** Load a canvas document produced by the model. */
2259
- const applyCanvasDoc = (doc, remoteAt) => {
2372
+ const applyCanvasDoc = (doc, remoteAt, fromRemote) => {
2260
2373
  if (!doc || !Array.isArray(doc.nodes)) return false;
2261
2374
  const merge = doc.mode === 'merge';
2262
2375
  if (!merge && !doc.nodes.length) return false;
2263
2376
  pushSnapshot();
2264
2377
  const stamp = typeof remoteAt === 'number' ? remoteAt : (typeof doc.at === 'number' ? doc.at : null);
2265
2378
  applyStamp.current = stamp;
2379
+ if (fromRemote) {
2380
+ skipDirtyOnce.current = true;
2381
+ setDirty(false);
2382
+ }
2383
+ if (typeof doc.enabled === 'boolean') {
2384
+ setEnabled(doc.enabled);
2385
+ }
2266
2386
  const removedNodes = new Set(doc.removeNodes || []);
2267
2387
  const rawIncomingEdges = Array.isArray(doc.edges) ? doc.edges : [];
2268
2388
  setNodes((existing) => {
@@ -2293,7 +2413,9 @@ window.__ModuleLoader__.load({
2293
2413
  });
2294
2414
  if (!merge) return incoming;
2295
2415
  const touched = new Set(incoming.map((n) => n.id));
2296
- const kept = existing.filter((n) => !touched.has(n.id) && !removedNodes.has(n.id));
2416
+ const kept = existing
2417
+ .filter((n) => !touched.has(n.id) && !removedNodes.has(n.id))
2418
+ .map((n) => (n.id === 'lead' && typeof doc.task === 'string' ? { ...n, task: doc.task } : n));
2297
2419
  return kept.concat(incoming);
2298
2420
  });
2299
2421
  setEdges((existing) => {
@@ -2315,7 +2437,7 @@ window.__ModuleLoader__.load({
2315
2437
  return kept.concat(added);
2316
2438
  });
2317
2439
  setSelectedIds([]);
2318
- setStatusById({});
2440
+ snapshotStaleCatalog();
2319
2441
  if (!merge) {
2320
2442
  setRunsById({});
2321
2443
  setTimeout(() => fitView(nodesRef.current), 0);
@@ -2377,7 +2499,7 @@ window.__ModuleLoader__.load({
2377
2499
  const valid = canvas && Array.isArray(canvas.nodes)
2378
2500
  && (canvas.mode === 'merge' || canvas.nodes.length > 0)
2379
2501
  && canvas.nodes.every((n) => n && typeof n.id === 'string');
2380
- if (valid && applyCanvasDoc(canvas, doc.at)) {
2502
+ if (valid && applyCanvasDoc(canvas, doc.at, true)) {
2381
2503
  flash(t('generated'));
2382
2504
  setSyncNote(t('syncApplied'));
2383
2505
  setTimeout(() => setSyncNote(''), 4000);
@@ -2400,6 +2522,7 @@ window.__ModuleLoader__.load({
2400
2522
  doc = JSON.parse(text.slice(start, end + 1));
2401
2523
  } catch (_e) { flash(t('importBad')); return; }
2402
2524
  if (!applyCanvasDoc(doc.canvas || doc)) { flash(t('importBad')); return; }
2525
+ if (enabled) setTimeout(() => pushPlan(true), 0);
2403
2526
  flash(t('importOk') + (doc.canvas || doc).nodes.length);
2404
2527
  };
2405
2528
  try {
@@ -2415,10 +2538,14 @@ window.__ModuleLoader__.load({
2415
2538
  const preset = presets[name];
2416
2539
  if (!preset || !Array.isArray(preset.nodes) || !Array.isArray(preset.edges)) { flash(t('invalidPreset')); return; }
2417
2540
  pushSnapshot();
2541
+ if (enabled) {
2542
+ skipDirtyOnce.current = true;
2543
+ pushPlan(true, preset.nodes, preset.edges);
2544
+ }
2418
2545
  setNodes(preset.nodes);
2419
2546
  setEdges(preset.edges);
2420
2547
  setSelectedIds([]);
2421
- setStatusById({});
2548
+ snapshotStaleCatalog();
2422
2549
  setRunsById({});
2423
2550
  setPresetOpen(null);
2424
2551
  setTimeout(() => fitView(preset.nodes), 0);
@@ -2430,10 +2557,14 @@ window.__ModuleLoader__.load({
2430
2557
  const clonedNodes = tpl.nodes.map((n) => ({ ...n }));
2431
2558
  const clonedEdges = tpl.edges.map((e) => ({ ...e }));
2432
2559
  pushSnapshot();
2560
+ if (enabled) {
2561
+ skipDirtyOnce.current = true;
2562
+ pushPlan(true, clonedNodes, clonedEdges);
2563
+ }
2433
2564
  setNodes(clonedNodes);
2434
2565
  setEdges(clonedEdges);
2435
2566
  setSelectedIds([]);
2436
- setStatusById({});
2567
+ snapshotStaleCatalog();
2437
2568
  setRunsById({});
2438
2569
  setPresetOpen(null);
2439
2570
  setTimeout(() => fitView(clonedNodes), 0);
@@ -2520,6 +2651,9 @@ window.__ModuleLoader__.load({
2520
2651
  onClick: () => { updateNode(node.id, { fallbackModel: m.model, fallbackProvider: m.provider }); setOpenModelFor(null); },
2521
2652
  }, m.modelName || m.model));
2522
2653
  }
2654
+ if (models.length === 1) {
2655
+ rows.push(h('div', { key: 'single-hint', style: S.presetEmpty }, t('singleModelHint')));
2656
+ }
2523
2657
  return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
2524
2658
  h('button', {
2525
2659
  style: S.selectBtn,
@@ -2632,6 +2766,7 @@ window.__ModuleLoader__.load({
2632
2766
  }
2633
2767
  const reachableIds = reachableFrom(nodes, edges);
2634
2768
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
2769
+ const deadEndIds = deadEndNodeIds(nodes, edges);
2635
2770
 
2636
2771
  // Identify intermediate/final Lead nodes whose upstream subagents are all
2637
2772
  // finished and whose downstream has not started yet ("Ready for Lead").
@@ -2672,6 +2807,7 @@ window.__ModuleLoader__.load({
2672
2807
  const isCompletedLink = enabled && !highlighted && statusById[edge.from] === 'done'
2673
2808
  && (statusById[edge.to] === 'done' || statusById[edge.to] === 'running' || leadReadyIds.has(edge.to));
2674
2809
  const dimmed = hasSel && !linkedToSel && !highlighted && !isFlowing;
2810
+ const strokeColor = highlighted ? '#e5534b' : color;
2675
2811
  const baseWidth = highlighted ? 3 : (linkedToSel || isFlowing ? 2.6 : 2);
2676
2812
  const baseOpacity = dimmed ? 0.26 : (isFlowing || linkedToSel ? 1 : (isCompletedLink ? 0.92 : 0.78));
2677
2813
  const useGlow = fxLevel === 'vivid' && !dimmed && (highlighted || isFlowing || linkedToSel || edge.type !== 'prompt');
@@ -2679,13 +2815,39 @@ window.__ModuleLoader__.load({
2679
2815
  const showBead = isFlowing && fxLevel === 'vivid';
2680
2816
 
2681
2817
  return h('g', { key: edge.id, style: { pointerEvents: 'none' } },
2818
+ // Vector halo layers instead of an SVG objectBoundingBox <filter>, which
2819
+ // Chromium clips to 0px height on strictly horizontal links (from.y === to.y).
2820
+ useGlow && h('path', {
2821
+ d,
2822
+ stroke: strokeColor,
2823
+ strokeWidth: baseWidth + 7,
2824
+ strokeOpacity: showDashFlow ? 0.1 : 0.16,
2825
+ strokeLinecap: 'round',
2826
+ fill: 'none',
2827
+ }),
2828
+ useGlow && h('path', {
2829
+ d,
2830
+ stroke: strokeColor,
2831
+ strokeWidth: baseWidth + 3.2,
2832
+ strokeOpacity: showDashFlow ? 0.18 : 0.3,
2833
+ strokeLinecap: 'round',
2834
+ fill: 'none',
2835
+ }),
2682
2836
  h('path', {
2683
2837
  d,
2684
- stroke: highlighted ? '#e5534b' : color,
2838
+ stroke: strokeColor,
2685
2839
  strokeWidth: baseWidth,
2686
2840
  strokeOpacity: showDashFlow ? 0.35 : baseOpacity,
2687
2841
  fill: 'none',
2688
- filter: useGlow ? 'url(#dsh-wc-glow)' : undefined,
2842
+ }),
2843
+ showDashFlow && fxLevel === 'vivid' && h('path', {
2844
+ d,
2845
+ className: 'dsh-wc-edge-flow',
2846
+ stroke: color,
2847
+ strokeWidth: 6.4,
2848
+ strokeOpacity: 0.28,
2849
+ strokeLinecap: 'round',
2850
+ fill: 'none',
2689
2851
  }),
2690
2852
  showDashFlow && h('path', {
2691
2853
  d,
@@ -2694,13 +2856,10 @@ window.__ModuleLoader__.load({
2694
2856
  strokeWidth: fxLevel === 'vivid' ? 2.8 : 2.4,
2695
2857
  strokeLinecap: 'round',
2696
2858
  fill: 'none',
2697
- filter: fxLevel === 'vivid' ? 'url(#dsh-wc-glow)' : undefined,
2698
2859
  }),
2699
- showBead && h('circle', {
2700
- r: 3.3,
2701
- fill: color,
2702
- filter: 'url(#dsh-wc-glow)',
2703
- },
2860
+ showBead && h('g', null,
2861
+ h('circle', { r: 6.5, fill: color, fillOpacity: 0.28 }),
2862
+ h('circle', { r: 3.3, fill: color }),
2704
2863
  h('animateMotion', {
2705
2864
  dur: '1.25s',
2706
2865
  repeatCount: 'indefinite',
@@ -2832,6 +2991,12 @@ window.__ModuleLoader__.load({
2832
2991
  onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
2833
2992
  onClick: () => { setMenuOpen(false); autoLayout(); },
2834
2993
  }, t('autoLayoutBtn')),
2994
+ h('div', {
2995
+ style: { ...S.moreRow, color: '#e5534b' },
2996
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
2997
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
2998
+ onClick: () => { clearCanvas(); },
2999
+ }, t('clearCanvasBtn')),
2835
3000
  h('div', {
2836
3001
  style: S.moreRow,
2837
3002
  onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
@@ -2889,6 +3054,12 @@ window.__ModuleLoader__.load({
2889
3054
  const names = Object.keys(presets);
2890
3055
  const templates = builtinTemplates(lang);
2891
3056
  return h('div', { style: S.presetMenu, onMouseDown: (e) => e.stopPropagation() },
3057
+ h('div', {
3058
+ style: { ...S.presetRow, color: C.accent, fontWeight: 500, borderBottom: '1px solid ' + C.border, marginBottom: '4px', paddingBottom: '6px', borderRadius: '4px 4px 0 0' },
3059
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
3060
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
3061
+ onClick: () => clearCanvas(),
3062
+ }, h('span', { style: S.presetRowText }, t('newBlankCanvas'))),
2892
3063
  h('div', { style: S.menuHead }, t('builtinTemplates')),
2893
3064
  templates.map((tpl) => h('div', {
2894
3065
  key: tpl.id,
@@ -2988,15 +3159,6 @@ window.__ModuleLoader__.load({
2988
3159
  },
2989
3160
  },
2990
3161
  h('svg', { width: contentW, height: contentH, style: { position: 'absolute', left: 0, top: 0, pointerEvents: 'none', overflow: 'visible' } },
2991
- fxLevel === 'vivid' && h('defs', null,
2992
- h('filter', { id: 'dsh-wc-glow', x: '-30%', y: '-30%', width: '160%', height: '160%' },
2993
- h('feGaussianBlur', { stdDeviation: '2.2', result: 'blur' }),
2994
- h('feMerge', null,
2995
- h('feMergeNode', { in: 'blur' }),
2996
- h('feMergeNode', { in: 'SourceGraphic' }),
2997
- ),
2998
- ),
2999
- ),
3000
3162
  h('g', null, edgeEls),
3001
3163
  cutPath.length > 1 && h('polyline', {
3002
3164
  points: cutPath.map((pt) => (pt.x + WORLD_PAD) + ',' + (pt.y + WORLD_PAD)).join(' '),
@@ -3036,6 +3198,7 @@ window.__ModuleLoader__.load({
3036
3198
  }),
3037
3199
  );
3038
3200
  const isOrphan = node.id !== 'lead' && !reachableIds.has(node.id);
3201
+ const isDeadEnd = deadEndIds.has(node.id);
3039
3202
  const isSelected = selectedSet.has(node.id);
3040
3203
  const nodeStatus = enabled ? statusById[node.id] : undefined;
3041
3204
  const isLeadReady = leadReadyIds.has(node.id);
@@ -3053,7 +3216,9 @@ window.__ModuleLoader__.load({
3053
3216
  ? { border: '1.5px solid rgba(229,83,75,0.8)', boxShadow: '0 0 12px rgba(229,83,75,0.18)' }
3054
3217
  : isDone
3055
3218
  ? { border: '1px solid rgba(63,185,80,0.55)' }
3056
- : null;
3219
+ : isDeadEnd
3220
+ ? { border: '1px solid rgba(210,153,34,0.55)' }
3221
+ : null;
3057
3222
  const topBarBg = (isRunning || isLeadReady) && fxLevel === 'vivid'
3058
3223
  ? (isLeadKind
3059
3224
  ? 'linear-gradient(90deg, #2f81f7 0%, #79c0ff 50%, #2f81f7 100%)'
@@ -3083,6 +3248,11 @@ window.__ModuleLoader__.load({
3083
3248
  }),
3084
3249
  h('div', { style: S.nodeHeader }),
3085
3250
  h('div', { style: S.bandDivider }),
3251
+ isDeadEnd && h('div', {
3252
+ style: S.warnChip,
3253
+ title: t('tipDeadEnd'),
3254
+ onMouseDown: (e) => e.stopPropagation(),
3255
+ }, '⚠ ', t('stDeadEnd')),
3086
3256
  (() => {
3087
3257
  const latestRun = !isLeadKind ? runsById[node.id] : null;
3088
3258
  const statusColor = isLeadReady ? '#2f81f7'
@@ -3260,7 +3430,7 @@ window.__ModuleLoader__.load({
3260
3430
  try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
3261
3431
  }
3262
3432
  },
3263
- __test: { topoOrder, wouldCycle, layoutGraph, builtinTemplates, nextEffectLevel, zoomAroundPoint, scrubZoom, buildWorkflowScript, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
3433
+ __test: { topoOrder, wouldCycle, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, zoomAroundPoint, scrubZoom, buildWorkflowScript, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
3264
3434
  };
3265
3435
  },
3266
3436
  });
package/docs/MECHANISM.md CHANGED
@@ -62,11 +62,11 @@ When `canvas_workflow` runs, `executePlan` executes the following pipeline:
62
62
  1. **Entry stripping & task override**: The entry `lead` node is stripped (`withoutEntry`) and never spawned. If `args.task` is provided, it overrides `plan.task` for this run (allowing blank-task templates to be reused straight from chat).
63
63
  2. **Cycle validation (Kahn topological sort)**: `orderNodes` validates the DAG is acyclic (the client also blocks cycles interactively via `wouldCycle`).
64
64
  3. **Reachability pruning**: BFS from `'lead'` filters out disconnected nodes. Unreachable nodes are drawn dashed, skipped at run time, and listed in `skipped` without burning tokens.
65
- 4. **Parallel waves & resumable pauses**:
65
+ 4. **Event-driven concurrency pool & resumable pauses**:
66
66
  - Progress per session is tracked in `runBySession` (`{ sig, done, results, labels, failed }`).
67
- - Each iteration finds every remaining node whose dependencies are all in `done`:
68
- - Ready **subagent nodes** run in parallel via `Promise.all`, up to **4 per wave** (`MAX_PARALLEL = 4`).
69
- - When only **Lead nodes** are ready and no `leadResult` was passed, execution pauses with `status: "need-lead"`, returning collected results, any failures, and `session` child IDs.
67
+ - Instead of a strict per-wave barrier, the executor runs an **event-driven concurrency pool (`inFlight` + `Promise.race`, `MAX_PARALLEL = 4`)**:
68
+ - The instant any running subagent finishes, newly unblocked downstream subagents launch immediately — fast branches never stall waiting for slower siblings.
69
+ - Once no runnable subagents remain and only downstream **non-entry Lead nodes** are ready (entry Lead never pauses) without a `leadResult`, execution pauses with `status: "need-lead"`, returning collected results, any failures, and `session` child IDs.
70
70
  - The conversation performs that Lead step and calls `canvas_workflow({ leadResult: "..." })` to resume seamlessly.
71
71
  - Changing the graph (different plan `sig`) or passing `reset: true` discards paused progress and restarts cleanly.
72
72
 
@@ -59,12 +59,12 @@ flowchart LR
59
59
  1. **入口剥离与任务解析**:剥离作为总任务容器的入口节点 `lead`(永不作为子代理执行)。若调用时传入 `task` 参数,则覆盖入口 Lead 的总任务(方便直接复用空任务预设)。
60
60
  2. **成环校验(Kahn 拓扑排序)**:用 `orderNodes` 校验 DAG 无环(客户端手动画线时也会用 `wouldCycle` 即时拦截)。
61
61
  3. **可达性剪枝**:从入口 `lead` 做广度优先遍历,不可达的孤立节点在画布上显示为虚线,运行时被自动跳过并列入 `skipped`,不会消耗 Token。
62
- 4. **波次并行与暂停续跑**:
62
+ 4. **事件驱动并发池与暂停续跑**:
63
63
  - 每个会话的运行进度保存在 `runBySession`(包含计划签名 `sig`、`done`、`results`、`labels`、`failed`);
64
- - 每轮循环找出所有依赖均已完成的就绪节点:
65
- - 若存在就绪的**子代理节点**,每次最多取 **4 个**(`MAX_PARALLEL = 4`)通过 `Promise.all` 并行执行;
66
- - 若就绪节点只剩 **Lead 节点**且尚未收到 `leadResult`,执行器立刻暂停并返回 `status: "need-lead"`,把已收集的上游结果、失败汇总以及紫线关联的子会话 `childId` 全部交回主对话;
67
- - 主对话完成该 Lead 步骤后,再次调用 `canvas_workflow({ leadResult: "..." })`,执行器从断点无缝继续下一波次;
64
+ - 执行器维护一个上限为 **4 并发**(`MAX_PARALLEL = 4`)的**动态并发池(`inFlight` + `Promise.race`)**,而非同步屏障:
65
+ - 只要有任意在跑子代理完成、空出并发槽位,**任何依赖已满足的下游子代理会立刻启动**,不再傻等同层较慢的兄弟节点;
66
+ - 直到当前所有可执行子代理全部跑完、仅剩 **非入口 Lead 节点**就绪且尚未收到 `leadResult` 时,执行器暂停并返回 `status: "need-lead"`(入口 Lead 仅承载总任务,不会触发暂停),把已收集结果、失败汇总以及紫线 `childId` 交回主对话;
67
+ - 主对话完成该 Lead 步骤后,再次调用 `canvas_workflow({ leadResult: "..." })`,执行器从断点无缝继续;
68
68
  - 若中途修改了画布(计划签名 `sig` 变化)或显式传入 `reset: true`,则丢弃旧进度从头重跑。
69
69
 
70
70
  ```mermaid