dsh-workflow-canvas 1.3.0 → 1.4.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
@@ -31,6 +31,17 @@ window.__ModuleLoader__.load({
31
31
  const KIND = 'workflow';
32
32
  const STORAGE_PREFIX = 'dsh-workflow-canvas:v1:';
33
33
  const PRESET_KEY = STORAGE_PREFIX + 'presets';
34
+ const SHORTCUTS_KEY = STORAGE_PREFIX + 'shortcuts';
35
+ const DEFAULT_SHORTCUTS = {
36
+ addNode: 'Shift+A',
37
+ duplicate: 'Shift+D',
38
+ delete: 'Delete',
39
+ undo: 'Ctrl+Z',
40
+ fitView: '',
41
+ autoLayout: '',
42
+ toggleDir: '',
43
+ };
44
+ const SHORTCUT_ORDER = ['addNode', 'duplicate', 'delete', 'undo', 'fitView', 'autoLayout', 'toggleDir'];
34
45
 
35
46
  const NODE_W = 216;
36
47
  const NODE_H = 234;
@@ -181,12 +192,12 @@ window.__ModuleLoader__.load({
181
192
  '6. 连好后点「● 已启用」,然后对对话说「跑一次」,由我调用执行。',
182
193
  '7. 遇到 Lead 节点会暂停,我做完再把结果交回去继续。',
183
194
  '8. 没连线的节点显示为虚线,运行时会被跳过。',
184
- '9. 右键按住划过一条连线可以切断;可在「⋯」里关掉这个手势。',
195
+ '9. 右键单击节点 / 连线 / 空白处可弹出快捷菜单(含线上插点、复制删除、新建节点等);按住右键划过连线可切断(可在「⋯」开关)。',
185
196
  '10. 点右上角「☰ 预设」顶部即可保存当前画布,开新对话时一键载入跨会话复用。',
186
197
  '11. 你可以直接让我改画布:说「把那三个节点的分工改成…」,我会就地修改,不动你摆的位置。',
187
198
  '12. session 线连到 Lead 时,我会在暂停那步拿到那个子代理的会话,可以继续追问它。',
188
199
  '13. 按住鼠标中键(或空格 + 左键)拖动画布平移;点击子代理节点左下角状态可直达它的对话记录。',
189
- '14. 快捷键:Shift+A 在光标处新建节点,Ctrl+D 复制选中节点,Delete 批量删除,Ctrl+Z 撤销,Esc 关闭弹窗。',
200
+ '14. 快捷键:默认 Shift+A 新建节点,Shift+D 复制节点与连线,Delete 删除,Ctrl+Z 撤销,Esc 关闭弹窗(可在「⋯ → 快捷键设置」自定义)。',
190
201
  ].join('\n'),
191
202
  openChat: '会话',
192
203
  tipOpenRun: '点击打开该子代理的对话记录',
@@ -224,6 +235,41 @@ window.__ModuleLoader__.load({
224
235
  condSideR: '右出',
225
236
  condSideL: '左出',
226
237
  tipCondSide: '竖排模式下切换分支输出口在左侧或右侧',
238
+ refsBtn: '参考',
239
+ refsTitleGlobal: '全局参考 / 约束(注入所有节点)',
240
+ refsTitleNode: '节点参考 / 约束',
241
+ refsAdd: '+ 添加参考',
242
+ refsPh: '文件路径、URL 或约束条款,如 src/auth.js',
243
+ refsEmpty: '点击下方按钮添加参考文件、路径或规范约束(最多 16 条)',
244
+ tipRefs: '附加参考文件、目录或约束清单,运行时自动注入提示词',
245
+ delRefTip: '删除该参考项',
246
+ ctxNodeTitle: '节点操作',
247
+ ctxEdgeTitle: '连线操作',
248
+ ctxCanvasTitle: '画布操作',
249
+ ctxDup: '复制节点',
250
+ ctxDelNode: '删除节点',
251
+ ctxOpenChat: '打开子代理对话 ↗',
252
+ ctxEditText: '展开编辑文本',
253
+ ctxManageRefs: '管理参考清单',
254
+ ctxDelEdge: '删除连线',
255
+ ctxInsertAgent: '在此插入子代理',
256
+ ctxInsertCond: '在此插入条件节点',
257
+ ctxLangToggle: '界面语言',
258
+ shortcutsMenu: '⌨ 快捷键设置',
259
+ shortcutsTitle: '快捷键设置',
260
+ shortcutsHint: '点击右侧按键框后按下新组合键;按 Esc 取消录制,点 × 清除绑定。',
261
+ shortcutsReset: '恢复默认',
262
+ shortcutsPress: '请按键…',
263
+ shortcutsUnset: '未设置',
264
+ shortcutsResetOk: '快捷键已恢复默认',
265
+ shortcutsConflict: '已更新快捷键(原冲突项已清空)',
266
+ scAddNode: '新建节点(光标处)',
267
+ scDuplicate: '复制选中节点与连线',
268
+ scDelete: '删除选中节点',
269
+ scUndo: '撤销',
270
+ scFitView: '全览居中',
271
+ scAutoLayout: '自动排版',
272
+ scToggleDir: '切换横排 / 竖排',
227
273
  fxLabel: '视觉效果',
228
274
  fxMinimal: '极简',
229
275
  fxStandard: '标准',
@@ -233,8 +279,8 @@ window.__ModuleLoader__.load({
233
279
  tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
234
280
  stDeadEnd: '无出边',
235
281
  tipDeadEnd: '该子代理没有下游连线,运行时不生效;请连入下游节点或终审 Lead',
236
- stSoloLead: '未接子代理',
237
- tipSoloLead: '该 Lead 仅串联了其他 Lead,未连入任何子代理,运行时不生效',
282
+ stSoloLead: '待填分工',
283
+ tipSoloLead: '该 Lead 阶段未连入子代理且分工为空,填写分工后即可作为主对话阶段运行',
238
284
  singleModelHint: '当前仅 1 个可用模型,暂无其它备用路由',
239
285
  importNone: '剪贴板里没有可识别的画布数据',
240
286
  importBad: '画布数据格式不对',
@@ -331,12 +377,12 @@ window.__ModuleLoader__.load({
331
377
  '6. Press ● ON, then ask in chat to run the canvas.',
332
378
  '7. The run pauses at every Lead node so the conversation can do that step.',
333
379
  '8. Unlinked nodes are dashed and skipped at run time.',
334
- '9. Hold the right button and sweep across a link to cut it; turn the gesture off under ⋯.',
380
+ '9. Right-click a node, wire, or blank canvas for context actions (insert on wire, duplicate/delete, add nodes); right-drag across a wire to cut it (toggle under ⋯).',
335
381
  '10. Open ☰ Presets to save the current canvas at the top and load it in any new chat.',
336
382
  '11. You can ask me to edit the canvas; I patch it in place and keep your layout.',
337
383
  '12. A session link into a Lead step hands me that child agent, so I can follow up with it.',
338
384
  '13. Hold the middle mouse button (or Space + drag) to pan; click a subagent status badge at the bottom-left to open its chat.',
339
- '14. Shortcuts: Shift+A adds a node at cursor, Ctrl+D duplicates, Delete removes selected, Ctrl+Z undoes, Esc closes popups.',
385
+ '14. Shortcuts: Shift+A adds a node at cursor, Shift+D duplicates nodes & links, Delete removes selected, Ctrl+Z undoes, Esc closes popups (customizable under ⋯ → Shortcuts).',
340
386
  ].join('\n'),
341
387
  openChat: 'Chat',
342
388
  tipOpenRun: 'Click to open this subagent conversation',
@@ -374,6 +420,41 @@ window.__ModuleLoader__.load({
374
420
  condSideR: 'Out R',
375
421
  condSideL: 'Out L',
376
422
  tipCondSide: 'Flip condition branch sockets between left and right edges in vertical mode',
423
+ refsBtn: 'Refs',
424
+ refsTitleGlobal: 'Global references / rules (all nodes)',
425
+ refsTitleNode: 'Node references / rules',
426
+ refsAdd: '+ Add ref',
427
+ refsPh: 'File path, URL, or rule, e.g. src/auth.js',
428
+ refsEmpty: 'Add reference files, paths, or rules injected into prompts (up to 16)',
429
+ tipRefs: 'Attach reference files, paths, or constraints injected at run time',
430
+ delRefTip: 'Remove this reference',
431
+ ctxNodeTitle: 'Node',
432
+ ctxEdgeTitle: 'Link',
433
+ ctxCanvasTitle: 'Canvas',
434
+ ctxDup: 'Duplicate',
435
+ ctxDelNode: 'Delete',
436
+ ctxOpenChat: 'Open chat ↗',
437
+ ctxEditText: 'Expand editor',
438
+ ctxManageRefs: 'Manage refs',
439
+ ctxDelEdge: 'Delete link',
440
+ ctxInsertAgent: 'Insert Subagent here',
441
+ ctxInsertCond: 'Insert Condition here',
442
+ ctxLangToggle: 'Language',
443
+ shortcutsMenu: '⌨ Shortcuts',
444
+ shortcutsTitle: 'Keyboard Shortcuts',
445
+ shortcutsHint: 'Click a key button then press a new combo. Press Esc to cancel, or × to clear.',
446
+ shortcutsReset: 'Reset defaults',
447
+ shortcutsPress: 'Press keys…',
448
+ shortcutsUnset: 'Unbound',
449
+ shortcutsResetOk: 'Shortcuts reset to defaults',
450
+ shortcutsConflict: 'Shortcut updated (cleared conflict)',
451
+ scAddNode: 'Add node at cursor',
452
+ scDuplicate: 'Duplicate nodes & links',
453
+ scDelete: 'Delete selected nodes',
454
+ scUndo: 'Undo',
455
+ scFitView: 'Fit all in view',
456
+ scAutoLayout: 'Auto layout',
457
+ scToggleDir: 'Toggle Horiz / Vert layout',
377
458
  fxLabel: 'Visual effects',
378
459
  fxMinimal: 'Minimal',
379
460
  fxStandard: 'Standard',
@@ -383,8 +464,8 @@ window.__ModuleLoader__.load({
383
464
  tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
384
465
  stDeadEnd: 'No out-link',
385
466
  tipDeadEnd: 'This subagent has no outgoing link and is skipped at run time; wire it into a downstream node or Lead',
386
- stSoloLead: 'Needs agent',
387
- tipSoloLead: 'This Lead only chains from another Lead with no subagent upstream, so it is skipped at run time',
467
+ stSoloLead: 'Needs role',
468
+ tipSoloLead: 'This chained Lead stage has no subagent upstream and an empty role; fill in a role to make it active',
388
469
  singleModelHint: 'Only 1 model available — no alternate fallback route',
389
470
  importNone: 'No canvas data found in the clipboard',
390
471
  importBad: 'Canvas data is malformed',
@@ -438,16 +519,16 @@ window.__ModuleLoader__.load({
438
519
  background: C.base, color: C.text, fontSize: '13px',
439
520
  },
440
521
  toolbar: {
441
- display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '6px',
442
- padding: '8px 10px', borderBottom: '1px solid ' + C.border, flex: '0 0 auto',
522
+ display: 'flex', alignItems: 'center', flexWrap: 'wrap', gap: '5px',
523
+ padding: '6px 8px', borderBottom: '1px solid ' + C.border, flex: '0 0 auto',
443
524
  },
444
525
  btn: {
445
- padding: '5px 10px', borderRadius: '6px', border: '1px solid ' + C.border,
446
- background: C.raised, color: C.text, fontSize: '12px', cursor: 'pointer', whiteSpace: 'nowrap',
526
+ padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.border,
527
+ background: C.raised, color: C.text, fontSize: '11px', cursor: 'pointer', whiteSpace: 'nowrap',
447
528
  },
448
529
  btnDirty: {
449
- padding: '5px 10px', borderRadius: '6px', border: '1px solid ' + C.accent,
450
- background: C.raised, color: C.accent, fontSize: '12px', fontWeight: 600,
530
+ padding: '4px 8px', borderRadius: '6px', border: '1px solid ' + C.accent,
531
+ background: C.raised, color: C.accent, fontSize: '11px', fontWeight: 600,
451
532
  cursor: 'pointer', whiteSpace: 'nowrap',
452
533
  },
453
534
  toolSep: {
@@ -480,6 +561,21 @@ window.__ModuleLoader__.load({
480
561
  background: C.elevated, color: C.dim, fontSize: '11px', fontWeight: 600,
481
562
  cursor: 'pointer', boxShadow: '0 4px 14px rgba(0,0,0,0.35)',
482
563
  },
564
+ floatZoomBar: {
565
+ position: 'absolute', right: '10px', bottom: '10px', zIndex: 30,
566
+ display: 'inline-flex', alignItems: 'center', gap: '4px',
567
+ padding: '3px 5px', borderRadius: '999px',
568
+ background: C.elevated, border: '1px solid ' + C.border,
569
+ boxShadow: '0 4px 14px rgba(0,0,0,0.28)',
570
+ },
571
+ floatZoomBtn: {
572
+ padding: '2px 6px', borderRadius: '999px', border: 'none',
573
+ background: 'transparent', color: C.text, fontSize: '11px',
574
+ cursor: 'pointer', whiteSpace: 'nowrap', lineHeight: '16px',
575
+ },
576
+ ctxDivider: {
577
+ height: '1px', background: C.border, opacity: 0.65, margin: '3px 4px',
578
+ },
483
579
  canvasWrap: {
484
580
  position: 'relative', flex: '1 1 auto', minHeight: '0',
485
581
  display: 'flex', flexDirection: 'column',
@@ -527,6 +623,19 @@ window.__ModuleLoader__.load({
527
623
  helpTitle: { flex: '1 1 auto', fontSize: '13px', fontWeight: 600, color: C.text },
528
624
  helpBody: { fontSize: '11px', lineHeight: '17px', color: C.dim },
529
625
  helpLine: { whiteSpace: 'pre-wrap' },
626
+ shortcutRow: {
627
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px',
628
+ padding: '6px 2px', borderBottom: '1px solid ' + C.border, fontSize: '11px', color: C.text,
629
+ },
630
+ shortcutKeyBtn: {
631
+ minWidth: '88px', padding: '3px 8px', borderRadius: '5px',
632
+ border: '1px solid ' + C.border, background: C.base, color: C.text,
633
+ fontSize: '11px', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',
634
+ cursor: 'pointer', textAlign: 'center', outline: 'none', whiteSpace: 'nowrap',
635
+ },
636
+ shortcutKeyRec: {
637
+ borderColor: C.accent, background: C.hover, color: C.accent, fontWeight: 600,
638
+ },
530
639
  presetBar: {
531
640
  marginLeft: 'auto', display: 'flex', alignItems: 'center',
532
641
  gap: '6px', position: 'relative', flex: '0 0 auto',
@@ -583,13 +692,13 @@ window.__ModuleLoader__.load({
583
692
  },
584
693
 
585
694
  title: {
586
- position: 'absolute', left: '10px', right: '10px', top: '8px', height: '18px',
695
+ position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
587
696
  fontWeight: 600, fontSize: '12px', lineHeight: '18px',
588
697
  border: 'none', background: 'transparent', color: C.text, padding: 0, margin: 0,
589
698
  outline: 'none', boxSizing: 'border-box', userSelect: 'text', zIndex: 2,
590
699
  },
591
700
  titleReadonly: {
592
- position: 'absolute', left: '10px', right: '10px', top: '8px', height: '18px',
701
+ position: 'absolute', left: '10px', right: '62px', top: '8px', height: '18px',
593
702
  fontWeight: 600, fontSize: '12px', lineHeight: '18px',
594
703
  overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', zIndex: 2,
595
704
  },
@@ -763,8 +872,7 @@ window.__ModuleLoader__.load({
763
872
  position: 'absolute', top: (ROW_H - PORT) / 2, width: PORT, height: PORT,
764
873
  borderRadius: '50%', background: C.raised, border: '2px solid ' + C.border,
765
874
  boxSizing: 'border-box', cursor: 'crosshair', zIndex: 6,
766
- /* a little extra grab area without changing the drawn dot */
767
- padding: 0, margin: -3, boxShadow: '0 0 0 3px transparent',
875
+ padding: 0, margin: 0, boxShadow: '0 0 0 3px transparent',
768
876
  },
769
877
  nodeDelete: {
770
878
  position: 'absolute', right: '-8px', top: '-8px', width: '18px', height: '18px',
@@ -795,26 +903,106 @@ window.__ModuleLoader__.load({
795
903
  padding: '9px 10px', zIndex: 65, boxShadow: '0 14px 32px rgba(0,0,0,0.52)',
796
904
  color: C.text, fontSize: '11px', lineHeight: '1.5', userSelect: 'text',
797
905
  },
906
+ refsPopover: {
907
+ position: 'absolute', left: '100%', top: '0', marginLeft: '8px', width: '268px',
908
+ background: C.elevated, color: C.text, border: '1px solid ' + C.border, borderRadius: '8px',
909
+ padding: '8px 9px', zIndex: 72, boxShadow: '0 12px 28px rgba(0,0,0,0.34)',
910
+ },
911
+ refsRow: {
912
+ display: 'flex', alignItems: 'center', gap: '4px', marginBottom: '5px',
913
+ },
914
+ refsInput: {
915
+ flex: '1 1 auto', minWidth: 0, height: '22px', boxSizing: 'border-box',
916
+ padding: '0 6px', borderRadius: '4px', border: '1px solid ' + C.border,
917
+ background: C.base, color: C.text, fontSize: '10px', outline: 'none', userSelect: 'text',
918
+ },
798
919
  };
799
920
 
800
921
  let hostCtx = null;
801
922
  let cachedModels = [];
802
923
 
924
+ function normalizeRefsUI(rawRefs) {
925
+ if (!Array.isArray(rawRefs) || !rawRefs.length) return [];
926
+ const out = [];
927
+ const seen = new Set();
928
+ for (const r of rawRefs) {
929
+ if (out.length >= 16) break;
930
+ const s = typeof r === 'string' ? r.trim() : '';
931
+ if (!s || seen.has(s)) continue;
932
+ seen.add(s);
933
+ out.push(s);
934
+ }
935
+ return out;
936
+ }
937
+
938
+ /**
939
+ * Clamp a floating context menu inside the canvas wrap, flipping left/up when near the
940
+ * right or bottom edge so menu items never clip off narrow sidebars.
941
+ */
942
+ function clampMenuPos(cx, cy, wrapW, wrapH, menuW, menuH) {
943
+ const pad = 8;
944
+ const sx = (cx + menuW > wrapW - pad)
945
+ ? Math.max(pad, cx - menuW)
946
+ : Math.max(pad, Math.min(wrapW - menuW - pad, cx));
947
+ const sy = (cy + menuH > wrapH - pad)
948
+ ? Math.max(pad, cy - menuH)
949
+ : Math.max(pad, Math.min(wrapH - menuH - pad, cy));
950
+ return { sx, sy };
951
+ }
952
+
953
+ /**
954
+ * Clone all selected non-entry nodes and every internal edge connecting two cloned nodes,
955
+ * preserving edge type and condition branch while isolating mutable array fields.
956
+ */
957
+ function cloneSelection(nodes, edges, selectedIds, stampOverride) {
958
+ const selSet = new Set((selectedIds || []).filter((id) => id !== 'lead'));
959
+ const sources = (nodes || []).filter((n) => n && selSet.has(n.id));
960
+ if (!sources.length) return { clones: [], clonedEdges: [] };
961
+ const stamp = stampOverride || Date.now().toString(36);
962
+ const idMap = new Map();
963
+ const clones = sources.map((src, idx) => {
964
+ const { runs: _runs, ...rest } = src;
965
+ const newId = 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4);
966
+ idMap.set(src.id, newId);
967
+ const clone = {
968
+ ...rest,
969
+ id: newId,
970
+ x: (src.x || 0) + 28,
971
+ y: (src.y || 0) + 28,
972
+ };
973
+ if (Array.isArray(src.refs)) clone.refs = src.refs.slice();
974
+ if (Array.isArray(src.branches)) clone.branches = src.branches.map((b) => ({ ...b }));
975
+ return clone;
976
+ });
977
+ const clonedEdges = [];
978
+ let edgeIdx = 0;
979
+ for (const e of edges || []) {
980
+ if (!e || !idMap.has(e.from) || !idMap.has(e.to)) continue;
981
+ const nextEdge = {
982
+ ...e,
983
+ id: 'e' + stamp + '_' + (edgeIdx++) + Math.random().toString(36).slice(2, 4),
984
+ from: idMap.get(e.from),
985
+ to: idMap.get(e.to),
986
+ };
987
+ clonedEdges.push(nextEdge);
988
+ }
989
+ return { clones, clonedEdges };
990
+ }
991
+
803
992
  function socketCenterY(i) {
804
993
  return SOCKET_BAND_TOP + i * ROW_H + ROW_H / 2;
805
994
  }
806
995
 
807
996
  /**
808
997
  * Determine which node kinds can legally receive a wire dragged out from `fromNode`.
809
- * Mirrors the canvas invariant that Lead -> Lead direct links are forbidden.
998
+ * All non-entry targets (agent, lead, condition) are valid, including Lead -> Lead stage chains.
810
999
  */
811
- function compatibleTargetsForWire(fromNode, _edgeType) {
812
- const fromLead = Boolean(fromNode && fromNode.kind === 'lead');
1000
+ function compatibleTargetsForWire(_fromNode, _edgeType) {
813
1001
  return {
814
1002
  agent: true,
815
- lead: !fromLead,
1003
+ lead: true,
816
1004
  condition: true,
817
- leadBlockedReason: fromLead ? 'leadToLeadBlocked' : '',
1005
+ leadBlockedReason: '',
818
1006
  };
819
1007
  }
820
1008
 
@@ -955,7 +1143,7 @@ window.__ModuleLoader__.load({
955
1143
 
956
1144
  function inputSocketPos(node, direction) {
957
1145
  if (direction === 'tb') return { x: node.x + NODE_W / 2, y: node.y };
958
- return { x: node.x, y: node.y + socketCenterY(0) };
1146
+ return { x: node.x, y: node.y + socketCenterY(0, node) };
959
1147
  }
960
1148
 
961
1149
  function outputSocketPos(fromNode, type, branch, direction) {
@@ -1059,7 +1247,7 @@ window.__ModuleLoader__.load({
1059
1247
  const x1 = from.x + WORLD_PAD + NODE_W;
1060
1248
  const y1 = from.y + WORLD_PAD + outputSocketY(from, type, branch);
1061
1249
  const x2 = to.x + WORLD_PAD;
1062
- const y2 = to.y + WORLD_PAD + socketCenterY(0);
1250
+ const y2 = to.y + WORLD_PAD + socketCenterY(0, to);
1063
1251
  const dx = Math.max(40, Math.abs(x2 - x1) * 0.5);
1064
1252
  return { x1, y1, c1x: x1 + dx, c1y: y1, c2x: x2 - dx, c2y: y2, x2, y2 };
1065
1253
  }
@@ -1139,8 +1327,8 @@ window.__ModuleLoader__.load({
1139
1327
 
1140
1328
  /**
1141
1329
  * Reachable non-entry Lead nodes that have zero reachable subagent upstream
1142
- * (chained solely from another Lead). Rendered dashed and skipped at run time;
1143
- * connecting any subagent into them makes them active immediately.
1330
+ * AND an empty `role` (blank placeholders). Filling a `role` turns them into
1331
+ * active main-conversation stage gates (Lead -> Lead chaining).
1144
1332
  */
1145
1333
  function soloLeadNodeIds(nodes, edges) {
1146
1334
  const list = Array.isArray(nodes) ? nodes : [];
@@ -1155,7 +1343,8 @@ window.__ModuleLoader__.load({
1155
1343
  const src = byId.get(e.from);
1156
1344
  return Boolean(src && src.kind !== 'lead');
1157
1345
  });
1158
- if (!hasAgentUp) out.add(n.id);
1346
+ const hasRole = Boolean(String(n.role || '').trim());
1347
+ if (!hasAgentUp && !hasRole) out.add(n.id);
1159
1348
  }
1160
1349
  return out;
1161
1350
  }
@@ -1533,39 +1722,43 @@ window.__ModuleLoader__.load({
1533
1722
  ? Math.max(1, Math.min(8, Math.floor(Number(opts.maxParallel))))
1534
1723
  : 4;
1535
1724
 
1536
- return {
1537
- plan: {
1538
- task,
1539
- maxParallel,
1540
- skipped: skipped.map((n) => n.label || n.id),
1541
- nodes: active.map((n) => {
1542
- const out = {
1543
- id: n.id,
1544
- kind: n.kind === 'lead' ? 'lead' : (n.kind === 'condition' ? 'condition' : 'agent'),
1545
- label: n.label || n.id,
1546
- role: n.role || '',
1547
- provider: n.provider || '',
1548
- model: n.model || '',
1549
- reasoning: n.reasoning || '',
1550
- preset: n.kind === 'condition' ? 'minimal' : (n.preset === 'minimal' ? 'minimal' : 'standard'),
1551
- keepSession: n.kind === 'condition' ? false : Boolean(n.keepSession),
1552
- memoryChildId: n.kind === 'condition' ? '' : (n.memoryChildId || ''),
1553
- // A structured link is the only thing that decides this: no separate switch.
1554
- structured: planEdges.some((e) => e.from === n.id && e.type === 'structured'),
1555
- fallbackModel: n.fallbackModel || '',
1556
- fallbackProvider: n.fallbackProvider || '',
1557
- };
1558
- if (out.kind === 'condition' && isCustomBranches(n)) {
1559
- out.branches = conditionBranchesForUI(n).map((b) => ({ id: b.id, label: b.label }));
1560
- }
1561
- if (out.kind === 'condition' && n.multiMatch) {
1562
- out.multiMatch = true;
1563
- }
1564
- return out;
1565
- }),
1566
- edges: planEdges,
1567
- },
1725
+ const entryRefs = normalizeRefsUI(entry.refs);
1726
+ const planOut = {
1727
+ task,
1728
+ maxParallel,
1729
+ skipped: skipped.map((n) => n.label || n.id),
1730
+ nodes: active.map((n) => {
1731
+ const kind = n.kind === 'lead' ? 'lead' : (n.kind === 'condition' ? 'condition' : 'agent');
1732
+ const out = {
1733
+ id: n.id,
1734
+ kind,
1735
+ label: n.label || n.id,
1736
+ role: n.role || '',
1737
+ provider: n.provider || '',
1738
+ model: n.model || '',
1739
+ reasoning: n.reasoning || '',
1740
+ preset: kind === 'condition' ? 'minimal' : (n.preset === 'minimal' ? 'minimal' : 'standard'),
1741
+ keepSession: kind === 'condition' ? false : Boolean(n.keepSession),
1742
+ memoryChildId: kind === 'condition' ? '' : (n.memoryChildId || ''),
1743
+ // A structured link is the only thing that decides this: no separate switch.
1744
+ structured: planEdges.some((e) => e.from === n.id && e.type === 'structured'),
1745
+ fallbackModel: n.fallbackModel || '',
1746
+ fallbackProvider: n.fallbackProvider || '',
1747
+ };
1748
+ if (kind === 'condition' && isCustomBranches(n)) {
1749
+ out.branches = conditionBranchesForUI(n).map((b) => ({ id: b.id, label: b.label }));
1750
+ }
1751
+ if (kind === 'condition' && n.multiMatch) {
1752
+ out.multiMatch = true;
1753
+ }
1754
+ const nodeRefs = normalizeRefsUI(n.refs);
1755
+ if (nodeRefs.length) out.refs = nodeRefs;
1756
+ return out;
1757
+ }),
1758
+ edges: planEdges,
1568
1759
  };
1760
+ if (entryRefs.length) planOut.refs = entryRefs;
1761
+ return { plan: planOut };
1569
1762
  }
1570
1763
 
1571
1764
  function loadCutMode() {
@@ -1624,6 +1817,101 @@ window.__ModuleLoader__.load({
1624
1817
  return PARALLEL_STEPS[(idx + 1) % PARALLEL_STEPS.length];
1625
1818
  }
1626
1819
 
1820
+ /** Canonicalize a shortcut string like "shift+d" or "cmd+z" -> "Shift+D" / "Ctrl+Z". */
1821
+ function normalizeShortcut(raw) {
1822
+ if (typeof raw !== 'string') return '';
1823
+ const trimmed = raw.trim();
1824
+ if (!trimmed) return '';
1825
+ const parts = trimmed.split('+').map((p) => p.trim()).filter(Boolean);
1826
+ let ctrl = false;
1827
+ let alt = false;
1828
+ let shift = false;
1829
+ let key = '';
1830
+ for (const p of parts) {
1831
+ const low = p.toLowerCase();
1832
+ if (low === 'ctrl' || low === 'control' || low === 'cmd' || low === 'meta' || low === 'mod') ctrl = true;
1833
+ else if (low === 'alt' || low === 'option') alt = true;
1834
+ else if (low === 'shift') shift = true;
1835
+ else if (low === 'del' || low === 'delete') key = 'Delete';
1836
+ else if (low === 'backspace') key = 'Backspace';
1837
+ else if (low === 'space' || p === ' ') key = 'Space';
1838
+ else if (low === 'enter' || low === 'return') key = 'Enter';
1839
+ else if (low === 'tab') key = 'Tab';
1840
+ else if (/^f\d{1,2}$/i.test(p)) key = p.toUpperCase();
1841
+ else if (p.length === 1) key = p.toUpperCase();
1842
+ else key = p.charAt(0).toUpperCase() + p.slice(1);
1843
+ }
1844
+ if (!key || key === 'Escape') return '';
1845
+ return (ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key;
1846
+ }
1847
+
1848
+ /** Extract a canonical shortcut string from a KeyboardEvent, or null for bare modifiers / Esc. */
1849
+ function formatShortcutFromEvent(ev) {
1850
+ if (!ev) return null;
1851
+ const rawKey = typeof ev.key === 'string' ? ev.key : '';
1852
+ if (!rawKey || rawKey === 'Control' || rawKey === 'Shift' || rawKey === 'Alt' || rawKey === 'Meta' || rawKey === 'Escape') {
1853
+ return null;
1854
+ }
1855
+ const code = typeof ev.code === 'string' ? ev.code : '';
1856
+ let key = '';
1857
+ if (/^Key[A-Z]$/.test(code)) key = code.slice(3);
1858
+ else if (/^Digit[0-9]$/.test(code)) key = code.slice(5);
1859
+ else if (rawKey === ' ') key = 'Space';
1860
+ else if (rawKey === 'Delete' || rawKey === 'Backspace' || rawKey === 'Enter' || rawKey === 'Tab') key = rawKey;
1861
+ else if (/^F\d{1,2}$/i.test(rawKey)) key = rawKey.toUpperCase();
1862
+ else if (rawKey.length === 1) key = rawKey.toUpperCase();
1863
+ else key = rawKey;
1864
+ const ctrl = Boolean(ev.ctrlKey || ev.metaKey);
1865
+ const alt = Boolean(ev.altKey);
1866
+ const shift = Boolean(ev.shiftKey);
1867
+ return normalizeShortcut((ctrl ? 'Ctrl+' : '') + (alt ? 'Alt+' : '') + (shift ? 'Shift+' : '') + key) || null;
1868
+ }
1869
+
1870
+ function matchesShortcut(ev, binding) {
1871
+ const target = normalizeShortcut(binding);
1872
+ if (!target) return false;
1873
+ const actual = formatShortcutFromEvent(ev);
1874
+ return Boolean(actual) && actual === target;
1875
+ }
1876
+
1877
+ function applyShortcutBinding(map, actionId, combo) {
1878
+ const next = { ...DEFAULT_SHORTCUTS, ...(map || {}) };
1879
+ const norm = normalizeShortcut(combo);
1880
+ let clearedConflict = false;
1881
+ if (norm) {
1882
+ for (const k of SHORTCUT_ORDER) {
1883
+ if (k !== actionId && normalizeShortcut(next[k]) === norm) {
1884
+ next[k] = '';
1885
+ clearedConflict = true;
1886
+ }
1887
+ }
1888
+ }
1889
+ next[actionId] = norm;
1890
+ return { next, clearedConflict };
1891
+ }
1892
+
1893
+ function loadShortcuts() {
1894
+ try {
1895
+ const raw = window.localStorage.getItem(SHORTCUTS_KEY);
1896
+ if (!raw) return { ...DEFAULT_SHORTCUTS };
1897
+ const parsed = JSON.parse(raw);
1898
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return { ...DEFAULT_SHORTCUTS };
1899
+ const out = { ...DEFAULT_SHORTCUTS };
1900
+ for (const k of SHORTCUT_ORDER) {
1901
+ if (k in parsed) out[k] = normalizeShortcut(parsed[k]);
1902
+ }
1903
+ return out;
1904
+ } catch (_e) {
1905
+ return { ...DEFAULT_SHORTCUTS };
1906
+ }
1907
+ }
1908
+
1909
+ function saveShortcuts(map) {
1910
+ try {
1911
+ window.localStorage.setItem(SHORTCUTS_KEY, JSON.stringify(map));
1912
+ } catch (_e) { /* ignore */ }
1913
+ }
1914
+
1627
1915
  /** Pick 'left' or 'right' anchor so a wrapped toolbar dropdown never clips off the pane edge. */
1628
1916
  function dropdownAlign(btnRect, containerRect, menuWidth) {
1629
1917
  if (!btnRect || !containerRect) return 'right';
@@ -1739,7 +2027,7 @@ window.__ModuleLoader__.load({
1739
2027
  if (!error) return this.props.children;
1740
2028
  const message = String((error && error.message) || error);
1741
2029
  const stack = String((error && error.stack) || '').slice(0, 900);
1742
- return h('div', {
2030
+ return h('div', {
1743
2031
  style: {
1744
2032
  padding: '12px', fontFamily: 'ui-monospace, monospace', fontSize: '11px',
1745
2033
  color: '#e5534b', whiteSpace: 'pre-wrap', overflow: 'auto', height: '100%',
@@ -1764,6 +2052,11 @@ window.__ModuleLoader__.load({
1764
2052
  const [menuAlign, setMenuAlign] = useState('right');
1765
2053
  const [presetAlign, setPresetAlign] = useState('right');
1766
2054
  const [helpOpen, setHelpOpen] = useState(false);
2055
+ const [shortcuts, setShortcuts] = useState(loadShortcuts);
2056
+ const shortcutsRef = useRef(shortcuts);
2057
+ shortcutsRef.current = shortcuts;
2058
+ const [shortcutsOpen, setShortcutsOpen] = useState(false);
2059
+ const [recordingAction, setRecordingAction] = useState(null);
1767
2060
  const [cutMode, setCutMode] = useState(loadCutMode);
1768
2061
  const [fxLevel, setFxLevel] = useState(loadEffectLevel);
1769
2062
  const [maxParallel, setMaxParallel] = useState(loadMaxParallel);
@@ -1793,6 +2086,8 @@ window.__ModuleLoader__.load({
1793
2086
  const pointerInsideRoot = useRef(false);
1794
2087
  const lastMouseRef = useRef(null);
1795
2088
  const [addMenu, setAddMenu] = useState(null);
2089
+ const [ctxMenu, setCtxMenu] = useState(null);
2090
+ const rightClickRef = useRef(null);
1796
2091
  const nodeDrag = useRef(null);
1797
2092
  const panDrag = useRef(null);
1798
2093
  const [panning, setPanning] = useState(false);
@@ -1811,6 +2106,7 @@ window.__ModuleLoader__.load({
1811
2106
  const [runsById, setRunsById] = useState({});
1812
2107
  const [runState, setRunState] = useState(null);
1813
2108
  const [decisionViewFor, setDecisionViewFor] = useState(null);
2109
+ const [refsEditFor, setRefsEditFor] = useState(null);
1814
2110
  const [sessionRunning, setSessionRunning] = useState(false);
1815
2111
  const [runTriggering, setRunTriggering] = useState(false);
1816
2112
  const runTriggeringRef = useRef(false);
@@ -2189,6 +2485,7 @@ window.__ModuleLoader__.load({
2189
2485
  if (!e.ctrlKey && findScrollableChild(e.target, e.deltaY)) return;
2190
2486
  e.preventDefault();
2191
2487
  absorbScroll();
2488
+ setCtxMenu(null);
2192
2489
  const rect = el.getBoundingClientRect();
2193
2490
  const mx = e.clientX - rect.left;
2194
2491
  const my = e.clientY - rect.top;
@@ -2436,6 +2733,63 @@ window.__ModuleLoader__.load({
2436
2733
  }
2437
2734
  setSelectedIds([newId]);
2438
2735
  setAddMenu(null);
2736
+ setCtxMenu(null);
2737
+ };
2738
+
2739
+ const deleteEdgeById = (edgeId) => {
2740
+ pushSnapshot();
2741
+ setEdges((es) => es.filter((e) => e.id !== edgeId));
2742
+ setCtxMenu(null);
2743
+ flash(t('linkCut') + ' ×1');
2744
+ };
2745
+
2746
+ const insertNodeOnEdge = (edgeId, kind, atWorld) => {
2747
+ const edge = edgesRef.current.find((e) => e.id === edgeId);
2748
+ if (!edge) { setCtxMenu(null); return; }
2749
+ pushSnapshot();
2750
+ const normKind = kind === 'condition' ? 'condition' : 'agent';
2751
+ const newId = 'n' + Date.now().toString(36) + Math.random().toString(36).slice(2, 4);
2752
+ const prefs = lastNodePrefsRef.current || {};
2753
+ setNodes((ns) => {
2754
+ const i = ns.length;
2755
+ const x = atWorld && typeof atWorld.x === 'number' ? Math.round(atWorld.x - NODE_W / 2) : 200;
2756
+ const y = atWorld && typeof atWorld.y === 'number' ? Math.round(atWorld.y - NODE_H / 2) : 140;
2757
+ const defaultLabel = normKind === 'condition'
2758
+ ? (lang === 'en' ? 'Condition ' + i : '条件判断 ' + i)
2759
+ : 'Node ' + i;
2760
+ return [...ns, {
2761
+ id: newId,
2762
+ kind: normKind,
2763
+ x,
2764
+ y,
2765
+ label: defaultLabel,
2766
+ provider: prefs.provider || '',
2767
+ model: prefs.model || '',
2768
+ reasoning: prefs.reasoning || '',
2769
+ preset: normKind === 'condition' ? 'minimal' : (prefs.preset || 'standard'),
2770
+ role: '',
2771
+ }];
2772
+ });
2773
+ setEdges((es) => {
2774
+ const kept = es.filter((e) => e.id !== edgeId);
2775
+ const e1 = {
2776
+ id: 'e' + Date.now().toString(36) + 'a',
2777
+ from: edge.from,
2778
+ to: newId,
2779
+ type: edge.type || 'prompt',
2780
+ };
2781
+ if (edge.branch) e1.branch = edge.branch;
2782
+ const e2 = {
2783
+ id: 'e' + Date.now().toString(36) + 'b',
2784
+ from: newId,
2785
+ to: edge.to,
2786
+ type: 'prompt',
2787
+ };
2788
+ if (normKind === 'condition') e2.branch = 'true';
2789
+ return kept.concat([e1, e2]);
2790
+ });
2791
+ setSelectedIds([newId]);
2792
+ setCtxMenu(null);
2439
2793
  };
2440
2794
 
2441
2795
  const updateNode = (id, patch) => {
@@ -2477,25 +2831,11 @@ window.__ModuleLoader__.load({
2477
2831
  };
2478
2832
 
2479
2833
  const duplicateSelected = () => {
2480
- const curSel = selectedIdsRef.current;
2481
- const curNodes = nodesRef.current;
2482
- const sources = curSel
2483
- .filter((id) => id !== 'lead')
2484
- .map((id) => curNodes.find((n) => n.id === id))
2485
- .filter(Boolean);
2486
- if (!sources.length) return;
2834
+ const { clones, clonedEdges } = cloneSelection(nodesRef.current, edgesRef.current, selectedIdsRef.current);
2835
+ if (!clones.length) return;
2487
2836
  pushSnapshot();
2488
- const stamp = Date.now().toString(36);
2489
- const clones = sources.map((src, idx) => {
2490
- const { runs: _runs, ...rest } = src;
2491
- return {
2492
- ...rest,
2493
- id: 'n' + stamp + '_' + idx + Math.random().toString(36).slice(2, 4),
2494
- x: (src.x || 0) + 28,
2495
- y: (src.y || 0) + 28,
2496
- };
2497
- });
2498
2837
  setNodes((ns) => ns.concat(clones));
2838
+ if (clonedEdges.length) setEdges((es) => es.concat(clonedEdges));
2499
2839
  setSelectedIds(clones.map((c) => c.id));
2500
2840
  flash(t('duplicatedNodes') + ' ×' + clones.length);
2501
2841
  };
@@ -2602,6 +2942,11 @@ window.__ModuleLoader__.load({
2602
2942
 
2603
2943
  /** Dragging any selected node moves the whole selection together. */
2604
2944
  const onNodeDown = (e, id) => {
2945
+ if (e.button === 2) {
2946
+ const tag = e.target && e.target.tagName;
2947
+ if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.stopPropagation();
2948
+ return;
2949
+ }
2605
2950
  if (e.button !== 0 || spaceDown.current) return;
2606
2951
  if (!contentRef.current) return;
2607
2952
  const node = nodes.find((n) => n.id === id);
@@ -2617,8 +2962,51 @@ window.__ModuleLoader__.load({
2617
2962
  setDragging(true);
2618
2963
  setOpenModelFor(null);
2619
2964
  setAddMenu(null);
2965
+ setCtxMenu(null);
2966
+ e.preventDefault();
2967
+ e.stopPropagation();
2968
+ };
2969
+
2970
+ const onNodeContextMenu = (e, node) => {
2971
+ const tag = e.target && e.target.tagName;
2972
+ if (tag === 'INPUT' || tag === 'TEXTAREA') return;
2620
2973
  e.preventDefault();
2621
2974
  e.stopPropagation();
2975
+ rightClickRef.current = null;
2976
+ const wrap = canvasWrapRef.current;
2977
+ if (!wrap) return;
2978
+ if (!selectedIdsRef.current.includes(node.id)) setSelectedIds([node.id]);
2979
+ const wrapRect = wrap.getBoundingClientRect();
2980
+ const pos = clampMenuPos(e.clientX - wrapRect.left, e.clientY - wrapRect.top, wrapRect.width, wrapRect.height, 180, 176);
2981
+ const world = pointTo(e);
2982
+ setCtxMenu({ kind: 'node', nodeId: node.id, sx: pos.sx, sy: pos.sy, wx: world.x, wy: world.y });
2983
+ setAddMenu(null);
2984
+ setMenuOpen(false);
2985
+ setPresetOpen(null);
2986
+ setOpenModelFor(null);
2987
+ setRoleEditFor(null);
2988
+ setDecisionViewFor(null);
2989
+ setRefsEditFor(null);
2990
+ };
2991
+
2992
+ const addNodeRef = (node) => {
2993
+ const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
2994
+ if (cur.length >= 16) return;
2995
+ pushSnapshot();
2996
+ updateNode(node.id, { refs: cur.concat(['']) });
2997
+ };
2998
+
2999
+ const updateNodeRef = (node, idx, text) => {
3000
+ const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
3001
+ cur[idx] = text;
3002
+ updateNode(node.id, { refs: cur });
3003
+ };
3004
+
3005
+ const removeNodeRef = (node, idx) => {
3006
+ const cur = Array.isArray(node.refs) ? node.refs.slice() : [];
3007
+ pushSnapshot();
3008
+ cur.splice(idx, 1);
3009
+ updateNode(node.id, { refs: cur });
2622
3010
  };
2623
3011
 
2624
3012
  const addConditionBranch = (node) => {
@@ -2812,12 +3200,12 @@ window.__ModuleLoader__.load({
2812
3200
  };
2813
3201
  }, []);
2814
3202
 
2815
- // Canvas keyboard shortcuts (Blender-style Shift+A, Ctrl+Z, Ctrl+D, Delete, Esc).
3203
+ // Configurable canvas keyboard shortcuts (defaults: Shift+A, Shift+D, Delete, Ctrl+Z, Esc).
2816
3204
  const keyActionsRef = useRef(null);
2817
3205
  keyActionsRef.current = {
2818
- undo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode,
2819
- addMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, decisionViewFor,
2820
- setAddMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setDecisionViewFor,
3206
+ undo, deleteSelected, duplicateSelected, openAddMenuAtCursor, addNode, fitView, autoLayout, toggleDirection, flash, t,
3207
+ addMenu, ctxMenu, roleEditFor, openModelFor, menuOpen, presetOpen, helpOpen, shortcutsOpen, recordingAction, decisionViewFor, refsEditFor,
3208
+ setAddMenu, setCtxMenu, setRoleEditFor, setOpenModelFor, setMenuOpen, setPresetOpen, setHelpOpen, setShortcutsOpen, setRecordingAction, setShortcuts, setDecisionViewFor, setRefsEditFor,
2821
3209
  };
2822
3210
  useEffect(() => {
2823
3211
  const isEditable = (target) => {
@@ -2828,19 +3216,41 @@ window.__ModuleLoader__.load({
2828
3216
  const onKey = (ev) => {
2829
3217
  const act = keyActionsRef.current;
2830
3218
  if (!act) return;
3219
+ if (act.recordingAction) {
3220
+ ev.preventDefault();
3221
+ ev.stopPropagation();
3222
+ if (ev.key === 'Escape') {
3223
+ act.setRecordingAction(null);
3224
+ return;
3225
+ }
3226
+ const combo = formatShortcutFromEvent(ev);
3227
+ if (!combo) return;
3228
+ const { next, clearedConflict } = applyShortcutBinding(shortcutsRef.current, act.recordingAction, combo);
3229
+ shortcutsRef.current = next;
3230
+ saveShortcuts(next);
3231
+ act.setShortcuts(next);
3232
+ act.setRecordingAction(null);
3233
+ if (clearedConflict) act.flash(act.t('shortcutsConflict'));
3234
+ return;
3235
+ }
2831
3236
  if (ev.key === 'Escape') {
2832
- if (act.addMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.decisionViewFor) {
3237
+ if (act.addMenu || act.ctxMenu || act.roleEditFor || act.openModelFor || act.menuOpen || act.presetOpen || act.helpOpen || act.shortcutsOpen || act.decisionViewFor || act.refsEditFor) {
2833
3238
  ev.preventDefault();
2834
3239
  act.setAddMenu(null);
3240
+ act.setCtxMenu(null);
2835
3241
  act.setRoleEditFor(null);
2836
3242
  act.setOpenModelFor(null);
2837
3243
  act.setMenuOpen(false);
2838
3244
  act.setPresetOpen(null);
2839
3245
  act.setHelpOpen(false);
3246
+ act.setShortcutsOpen(false);
3247
+ act.setRecordingAction(null);
2840
3248
  act.setDecisionViewFor(null);
3249
+ act.setRefsEditFor(null);
2841
3250
  }
2842
3251
  return;
2843
3252
  }
3253
+ if (act.shortcutsOpen) return;
2844
3254
  if (isEditable(ev.target)) return;
2845
3255
  if (act.addMenu) {
2846
3256
  const lf = act.addMenu.linkFrom || null;
@@ -2863,23 +3273,41 @@ window.__ModuleLoader__.load({
2863
3273
  const root = rootElRef.current;
2864
3274
  const activeInRoot = Boolean(root && document.activeElement && root.contains(document.activeElement));
2865
3275
  if (!pointerInsideRoot.current && !activeInRoot) return;
2866
- const mod = ev.ctrlKey || ev.metaKey;
2867
- if (!mod && !ev.altKey && ev.shiftKey && (ev.key === 'A' || ev.key === 'a')) {
3276
+ const sc = shortcutsRef.current || DEFAULT_SHORTCUTS;
3277
+ if (matchesShortcut(ev, sc.addNode)) {
2868
3278
  ev.preventDefault();
2869
3279
  act.openAddMenuAtCursor();
2870
3280
  return;
2871
3281
  }
2872
- if (mod && !ev.shiftKey && !ev.altKey && (ev.key === 'z' || ev.key === 'Z')) {
3282
+ if (matchesShortcut(ev, sc.undo)) {
2873
3283
  ev.preventDefault();
2874
3284
  act.undo();
2875
3285
  return;
2876
3286
  }
2877
- if (mod && !ev.shiftKey && !ev.altKey && (ev.key === 'd' || ev.key === 'D')) {
3287
+ if (matchesShortcut(ev, sc.duplicate)) {
2878
3288
  ev.preventDefault();
2879
3289
  act.duplicateSelected();
2880
3290
  return;
2881
3291
  }
2882
- if (!mod && !ev.altKey && (ev.key === 'Delete' || ev.key === 'Backspace')) {
3292
+ if (matchesShortcut(ev, sc.fitView)) {
3293
+ ev.preventDefault();
3294
+ act.fitView();
3295
+ return;
3296
+ }
3297
+ if (matchesShortcut(ev, sc.autoLayout)) {
3298
+ ev.preventDefault();
3299
+ act.autoLayout();
3300
+ return;
3301
+ }
3302
+ if (matchesShortcut(ev, sc.toggleDir)) {
3303
+ ev.preventDefault();
3304
+ act.toggleDirection();
3305
+ return;
3306
+ }
3307
+ const allBound = Object.values(sc).map(normalizeShortcut);
3308
+ const delHit = matchesShortcut(ev, sc.delete)
3309
+ || (normalizeShortcut(sc.delete) === 'Delete' && !allBound.includes('Backspace') && matchesShortcut(ev, 'Backspace'));
3310
+ if (delHit) {
2883
3311
  if (selectedIdsRef.current.length) {
2884
3312
  ev.preventDefault();
2885
3313
  act.deleteSelected();
@@ -2890,32 +3318,6 @@ window.__ModuleLoader__.load({
2890
3318
  return () => window.removeEventListener('keydown', onKey);
2891
3319
  }, []);
2892
3320
 
2893
- // Suppress the host context menu over the canvas while cutting is on.
2894
- useEffect(() => {
2895
- if (!cutMode) return undefined;
2896
- const inside = (ev) => {
2897
- const el = canvasElRef.current;
2898
- return Boolean(el) && ev.target instanceof Node && el.contains(ev.target);
2899
- };
2900
- const onCtx = (ev) => { if (inside(ev)) ev.preventDefault(); };
2901
- const onDown = (ev) => {
2902
- if (ev.button !== 2 || !inside(ev) || ev.target.closest('[data-node]')) return;
2903
- ev.preventDefault();
2904
- const start = pointTo(ev);
2905
- cutRef.current = start;
2906
- cutHits.current = new Set();
2907
- setCutPath([start]);
2908
- setCutVictims([]);
2909
- setDragging(true);
2910
- };
2911
- window.addEventListener('contextmenu', onCtx, true);
2912
- window.addEventListener('mousedown', onDown, true);
2913
- return () => {
2914
- window.removeEventListener('contextmenu', onCtx, true);
2915
- window.removeEventListener('mousedown', onDown, true);
2916
- };
2917
- }, [cutMode, sessionId]);
2918
-
2919
3321
  useEffect(() => {
2920
3322
  if (!dragging) return undefined;
2921
3323
  const move = (ev) => onCanvasMove(ev);
@@ -2930,22 +3332,20 @@ window.__ModuleLoader__.load({
2930
3332
 
2931
3333
  const onCanvasDown = (e) => {
2932
3334
  if (e.button === 2) {
2933
- if (!cutMode) return;
2934
3335
  e.preventDefault();
2935
3336
  try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
2936
3337
  const start = pointTo(e);
2937
- cutRef.current = start;
2938
- cutHits.current = new Set();
2939
- setCutPath([start]);
2940
- setCutVictims([]);
3338
+ rightClickRef.current = { clientX: e.clientX, clientY: e.clientY, start, moved: false };
2941
3339
  setDragging(true);
2942
3340
  return;
2943
3341
  }
2944
3342
  if (e.button !== 0) return;
2945
3343
  if (roleEditFor) setRoleEditFor(null);
2946
3344
  if (decisionViewFor) setDecisionViewFor(null);
3345
+ if (refsEditFor) setRefsEditFor(null);
2947
3346
  if (menuOpen) setMenuOpen(false);
2948
3347
  if (addMenu) setAddMenu(null);
3348
+ if (ctxMenu) setCtxMenu(null);
2949
3349
  if (presetOpen) setPresetOpen(null);
2950
3350
  e.preventDefault();
2951
3351
  try { window.getSelection().removeAllRanges(); } catch (_sel) { /* ignore */ }
@@ -2964,6 +3364,17 @@ window.__ModuleLoader__.load({
2964
3364
  commitView({ k: viewRef.current.k, x: pan.originX + dx, y: pan.originY + dy });
2965
3365
  return;
2966
3366
  }
3367
+ if (rightClickRef.current && !rightClickRef.current.moved) {
3368
+ if (Math.hypot(e.clientX - rightClickRef.current.clientX, e.clientY - rightClickRef.current.clientY) >= 6) {
3369
+ rightClickRef.current.moved = true;
3370
+ if (cutMode) {
3371
+ cutRef.current = rightClickRef.current.start;
3372
+ cutHits.current = new Set();
3373
+ setCutPath([rightClickRef.current.start]);
3374
+ setCutVictims([]);
3375
+ }
3376
+ }
3377
+ }
2967
3378
  if (nodeDrag.current) {
2968
3379
  const p = pointTo(e);
2969
3380
  const drag = nodeDrag.current;
@@ -3013,6 +3424,49 @@ window.__ModuleLoader__.load({
3013
3424
  };
3014
3425
 
3015
3426
  const onCanvasUp = (ev) => {
3427
+ if (rightClickRef.current) {
3428
+ const rc = rightClickRef.current;
3429
+ rightClickRef.current = null;
3430
+ if (!rc.moved) {
3431
+ const wrap = canvasWrapRef.current;
3432
+ if (wrap) {
3433
+ const wrapRect = wrap.getBoundingClientRect();
3434
+ const cx = rc.clientX - wrapRect.left;
3435
+ const cy = rc.clientY - wrapRect.top;
3436
+ const canvasSpot = { x: rc.start.x + WORLD_PAD, y: rc.start.y + WORLD_PAD };
3437
+ const threshold = Math.max(10, 14 / (viewRef.current.k || 1));
3438
+ const nodeMap = new Map(nodesRef.current.map((n) => [n.id, n]));
3439
+ let hitEdge = null;
3440
+ let bestDist = Infinity;
3441
+ for (const edge of edgesRef.current) {
3442
+ const source = nodeMap.get(edge.from);
3443
+ const target = nodeMap.get(edge.to);
3444
+ if (!source || !target) continue;
3445
+ const dist = distanceToEdge(canvasSpot, source, target, edge, directionRef.current);
3446
+ if (dist <= threshold && dist < bestDist) {
3447
+ bestDist = dist;
3448
+ hitEdge = edge;
3449
+ }
3450
+ }
3451
+ setAddMenu(null);
3452
+ setMenuOpen(false);
3453
+ setPresetOpen(null);
3454
+ setOpenModelFor(null);
3455
+ setRoleEditFor(null);
3456
+ setDecisionViewFor(null);
3457
+ setRefsEditFor(null);
3458
+ if (hitEdge) {
3459
+ const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 180, 120);
3460
+ setCtxMenu({ kind: 'edge', edgeId: hitEdge.id, sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
3461
+ } else {
3462
+ const pos = clampMenuPos(cx, cy, wrapRect.width, wrapRect.height, 186, 296);
3463
+ setCtxMenu({ kind: 'canvas', sx: pos.sx, sy: pos.sy, wx: rc.start.x, wy: rc.start.y });
3464
+ }
3465
+ }
3466
+ setDragging(false);
3467
+ return;
3468
+ }
3469
+ }
3016
3470
  if (cutRef.current) {
3017
3471
  cutRef.current = null;
3018
3472
  setDragging(false);
@@ -3107,33 +3561,56 @@ window.__ModuleLoader__.load({
3107
3561
  const byId = new Map(existing.map((n) => [n.id, n]));
3108
3562
  const placed = new Map(existing.map((n) => [n.id, { x: n.x, y: n.y }]));
3109
3563
  let addedCount = 0;
3564
+ const isTB = directionRef.current === 'tb';
3110
3565
  const incoming = doc.nodes.map((n, i) => {
3111
3566
  const prev = byId.get(n.id) || {};
3112
3567
  let x = typeof n.x === 'number' ? n.x : prev.x;
3113
3568
  let y = typeof n.y === 'number' ? n.y : prev.y;
3114
3569
  if (typeof x !== 'number' || typeof y !== 'number') {
3115
- // Place a newly patched node to the right of its first upstream node when possible.
3570
+ // Place a newly patched node downstream of its first upstream node,
3571
+ // respecting the active horizontal (lr) or vertical (tb) flow direction.
3116
3572
  const parentEdge = rawIncomingEdges.find((e) => e && e.to === n.id && placed.has(e.from));
3117
3573
  if (parentEdge) {
3118
3574
  const parentPos = placed.get(parentEdge.from);
3119
- const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.x - (parentPos.x + 300)) < 40).length;
3120
- x = parentPos.x + 300;
3121
- y = parentPos.y + siblingCount * 240;
3575
+ const parentNode = byId.get(parentEdge.from);
3576
+ if (isTB) {
3577
+ const targetY = parentPos.y + nodeHeight(parentNode) + 68;
3578
+ const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.y - targetY) < 40).length;
3579
+ x = parentPos.x + siblingCount * 292;
3580
+ y = targetY;
3581
+ } else {
3582
+ const siblingCount = Array.from(placed.values()).filter((p) => Math.abs(p.x - (parentPos.x + 300)) < 40).length;
3583
+ x = parentPos.x + 300;
3584
+ y = parentPos.y + siblingCount * 240;
3585
+ }
3122
3586
  } else {
3123
3587
  const leadPos = placed.get('lead') || { x: 40, y: 80 };
3124
- x = merge ? leadPos.x + 300 : 60 + i * 300;
3125
- y = merge ? leadPos.y + (addedCount + 1) * 240 : 80;
3588
+ if (isTB) {
3589
+ x = merge ? leadPos.x + addedCount * 292 : 40 + i * 292;
3590
+ y = merge ? leadPos.y + NODE_H + 68 : 80;
3591
+ } else {
3592
+ x = merge ? leadPos.x + 300 : 60 + i * 300;
3593
+ y = merge ? leadPos.y + (addedCount + 1) * 240 : 80;
3594
+ }
3126
3595
  }
3127
3596
  addedCount += 1;
3128
3597
  }
3129
3598
  placed.set(n.id, { x, y });
3130
3599
  return { ...prev, ...n, x, y };
3131
3600
  });
3132
- if (!merge) return incoming;
3601
+ if (!merge) {
3602
+ return isTB ? layoutGraph(incoming, rawIncomingEdges, 'tb') : incoming;
3603
+ }
3133
3604
  const touched = new Set(incoming.map((n) => n.id));
3134
3605
  const kept = existing
3135
3606
  .filter((n) => !touched.has(n.id) && !removedNodes.has(n.id))
3136
- .map((n) => (n.id === 'lead' && typeof doc.task === 'string' ? { ...n, task: doc.task } : n));
3607
+ .map((n) => {
3608
+ if (n.id !== 'lead') return n;
3609
+ const patch = {};
3610
+ if (typeof doc.task === 'string') patch.task = doc.task;
3611
+ if (Array.isArray(doc.refs)) patch.refs = doc.refs;
3612
+ return Object.keys(patch).length ? { ...n, ...patch } : n;
3613
+ });
3137
3614
  return kept.concat(incoming);
3138
3615
  });
3139
3616
  setEdges((existing) => {
@@ -3408,7 +3885,7 @@ window.__ModuleLoader__.load({
3408
3885
  if (models.length === 1) {
3409
3886
  rows.push(h('div', { key: 'single-hint', style: S.presetEmpty }, t('singleModelHint')));
3410
3887
  }
3411
- return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
3888
+ return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
3412
3889
  h('button', {
3413
3890
  style: S.selectBtn,
3414
3891
  type: 'button',
@@ -3454,7 +3931,7 @@ window.__ModuleLoader__.load({
3454
3931
  }, t('memLatestOpt')),
3455
3932
  ...history.map((item) => {
3456
3933
  const selectedRow = node.memoryChildId === item.childId;
3457
- return h('div', {
3934
+ return h('div', {
3458
3935
  key: item.childId,
3459
3936
  style: selectedRow ? { ...S.menuRow, background: C.hover, color: C.accent } : S.menuRow,
3460
3937
  title: item.childId,
@@ -3465,7 +3942,7 @@ window.__ModuleLoader__.load({
3465
3942
  }),
3466
3943
  !history.length && h('div', { key: 'mem-empty', style: S.presetEmpty }, t('memEmpty')),
3467
3944
  ];
3468
- return h('div', { style: { display: 'flex', alignItems: 'center', gap: '4px', flex: '1 1 auto', minWidth: 0 } },
3945
+ return h('div', { style: { display: 'flex', alignItems: 'center', gap: '4px', flex: '1 1 auto', minWidth: 0 } },
3469
3946
  toggleBtn,
3470
3947
  h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '0 0 64px', width: '64px' } },
3471
3948
  h('button', {
@@ -3505,7 +3982,7 @@ window.__ModuleLoader__.load({
3505
3982
  onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
3506
3983
  onClick: () => { updateNode(node.id, { reasoning: id }); setOpenModelFor(null); },
3507
3984
  }, labelOf(id)));
3508
- return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
3985
+ return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
3509
3986
  h('button', {
3510
3987
  style: S.selectBtn,
3511
3988
  type: 'button',
@@ -3562,7 +4039,7 @@ window.__ModuleLoader__.load({
3562
4039
  onClick: () => { updateNode(node.id, { provider: m.provider, model: m.model }); setOpenModelFor(null); },
3563
4040
  }, m.modelName || m.model));
3564
4041
  }
3565
- return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
4042
+ return h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
3566
4043
  h('button', {
3567
4044
  style: S.selectBtn,
3568
4045
  type: 'button',
@@ -3612,8 +4089,18 @@ window.__ModuleLoader__.load({
3612
4089
  const leadDoneIds = new Set();
3613
4090
  const hasCondNode = nodes.some((x) => x.kind === 'condition');
3614
4091
  if (enabled) {
4092
+ if (runState && runState.waitingLead && runState.waitingLead.id) {
4093
+ leadReadyIds.add(runState.waitingLead.id);
4094
+ }
4095
+ if (runState && Array.isArray(runState.done)) {
4096
+ for (const did of runState.done) {
4097
+ const dn = nodeById.get(did);
4098
+ if (dn && dn.kind === 'lead' && dn.id !== 'lead') leadDoneIds.add(did);
4099
+ }
4100
+ }
3615
4101
  for (const n of nodes) {
3616
4102
  if (n.kind !== 'lead' || n.id === 'lead' || !reachableIds.has(n.id)) continue;
4103
+ if (leadReadyIds.has(n.id) || leadDoneIds.has(n.id)) continue;
3617
4104
  const upIds = edges
3618
4105
  .filter((e) => e.to === n.id && e.from !== 'lead' && nodeById.has(e.from))
3619
4106
  .map((e) => e.from);
@@ -3764,7 +4251,7 @@ window.__ModuleLoader__.load({
3764
4251
  const condDec = decisionsById[node.id] || null;
3765
4252
  const matchedBranchIds = condDec && Array.isArray(condDec.branches) ? new Set(condDec.branches) : null;
3766
4253
  const onLeft = isTB && node.tbSide === 'left';
3767
- return h('div', { style: S.band },
4254
+ return h('div', { style: S.band },
3768
4255
  unifiedInSocket,
3769
4256
  !isTB && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
3770
4257
  branches.map((b) => {
@@ -3775,7 +4262,7 @@ window.__ModuleLoader__.load({
3775
4262
  ? (b.id === 'true' ? t('tipCondTrue') : t('tipCondFalse'))
3776
4263
  : t('tipBranchOut');
3777
4264
  const editKey = 'branch:' + node.id + ':' + b.id;
3778
- return h('div', {
4265
+ return h('div', {
3779
4266
  key: b.id,
3780
4267
  style: {
3781
4268
  ...S.condBranchRow,
@@ -3789,18 +4276,10 @@ window.__ModuleLoader__.load({
3789
4276
  alignItems: 'center',
3790
4277
  marginLeft: onLeft ? '10px' : 0,
3791
4278
  marginRight: onLeft ? 0 : '10px',
3792
- flexDirection: onLeft ? 'row-reverse' : 'row',
4279
+ gap: '2px',
3793
4280
  },
3794
4281
  onMouseDown: (e) => e.stopPropagation(),
3795
4282
  },
3796
- h('button', {
3797
- type: 'button',
3798
- style: { ...S.condBranchExpand, marginRight: onLeft ? 0 : '2px', marginLeft: onLeft ? '2px' : 0 },
3799
- title: t('tipExpandBranch'),
3800
- onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
3801
- onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
3802
- onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
3803
- }, '⤢'),
3804
4283
  h('input', {
3805
4284
  style: {
3806
4285
  ...S.condBranchInput,
@@ -3813,16 +4292,22 @@ window.__ModuleLoader__.load({
3813
4292
  onFocus: () => setSelectedIds([node.id]),
3814
4293
  onChange: (e) => renameConditionBranch(node, b.id, e.target.value),
3815
4294
  }),
3816
- branches.length > 2
3817
- ? h('button', {
3818
- type: 'button',
3819
- style: { ...S.condBranchDel, marginLeft: onLeft ? 0 : '2px', marginRight: onLeft ? '2px' : 0 },
3820
- title: t('delBranchTip'),
3821
- onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
3822
- onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
3823
- onClick: () => removeConditionBranch(node, b.id),
3824
- }, '×')
3825
- : h('span', { style: S.condBranchDelSpacer }),
4295
+ h('button', {
4296
+ type: 'button',
4297
+ style: { ...S.condBranchExpand, marginRight: 0 },
4298
+ title: t('tipExpandBranch'),
4299
+ onMouseEnter: (e) => { e.currentTarget.style.color = C.text; e.currentTarget.style.borderColor = b.color; },
4300
+ onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; e.currentTarget.style.borderColor = C.border; },
4301
+ onClick: () => setRoleEditFor(roleEditFor === editKey ? null : editKey),
4302
+ }, '⤢'),
4303
+ branches.length > 2 && h('button', {
4304
+ type: 'button',
4305
+ style: { ...S.condBranchDel, marginLeft: 0 },
4306
+ title: t('delBranchTip'),
4307
+ onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
4308
+ onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
4309
+ onClick: () => removeConditionBranch(node, b.id),
4310
+ }, '×'),
3826
4311
  ),
3827
4312
  roleEditFor === editKey && h('div', {
3828
4313
  style: { ...S.rolePopover, top: '-8px' },
@@ -3903,7 +4388,7 @@ window.__ModuleLoader__.load({
3903
4388
  !isEntry && h('span', { style: { ...S.rowLabel, position: 'absolute', left: '12px', top: '3px', pointerEvents: 'none' } }, inText),
3904
4389
  SOCKET_TYPES.map((sock) => {
3905
4390
  const outLinked = connectedOut.has(node.id + '|' + sock.id);
3906
- return h('div', { key: sock.id, style: S.row },
4391
+ return h('div', { key: sock.id, style: S.row },
3907
4392
  h('span', { style: { ...S.rowLabel, position: 'absolute', right: '12px' } }, sock.label),
3908
4393
  h('div', {
3909
4394
  style: {
@@ -3939,6 +4424,84 @@ window.__ModuleLoader__.load({
3939
4424
  .map((n) => n.id);
3940
4425
  };
3941
4426
 
4427
+ /** Compact "+ 参考" trigger docked cleanly in the top-right of every node header bar. */
4428
+ const refsControlBtn = (node) => {
4429
+ const count = normalizeRefsUI(node.refs).length;
4430
+ const isOpen = refsEditFor === node.id;
4431
+ return h('button', {
4432
+ type: 'button',
4433
+ style: {
4434
+ ...(count > 0 || isOpen ? S.condModeBtnOn : S.condAddBtn),
4435
+ position: 'absolute',
4436
+ top: '9px',
4437
+ right: '10px',
4438
+ zIndex: 7,
4439
+ whiteSpace: 'nowrap',
4440
+ flex: '0 0 auto',
4441
+ },
4442
+ title: t('tipRefs'),
4443
+ onMouseDown: (e) => e.stopPropagation(),
4444
+ onClick: (e) => {
4445
+ e.stopPropagation();
4446
+ setRoleEditFor(null);
4447
+ setRefsEditFor(isOpen ? null : node.id);
4448
+ },
4449
+ }, count > 0 ? (t('refsBtn') + '×' + count) : ('+ ' + t('refsBtn')));
4450
+ };
4451
+
4452
+ const refsPopoverEl = (node) => {
4453
+ if (refsEditFor !== node.id) return null;
4454
+ const list = Array.isArray(node.refs) ? node.refs : [];
4455
+ const isGlobal = node.id === 'lead';
4456
+ return h('div', {
4457
+ style: S.refsPopover,
4458
+ onMouseDown: (e) => e.stopPropagation(),
4459
+ },
4460
+ h('div', {
4461
+ style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '6px', fontSize: '10px', fontWeight: 600, color: C.dim },
4462
+ },
4463
+ h('span', null, (isGlobal ? t('refsTitleGlobal') : t('refsTitleNode')) + ' (' + list.length + '/16)'),
4464
+ h('button', {
4465
+ type: 'button',
4466
+ style: { background: 'transparent', border: 'none', color: C.dim, cursor: 'pointer', fontSize: '12px', padding: '0 2px' },
4467
+ onClick: () => setRefsEditFor(null),
4468
+ }, '×'),
4469
+ ),
4470
+ list.length === 0
4471
+ ? h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '6px', lineHeight: '1.4' } }, t('refsEmpty'))
4472
+ : h('div', { style: { maxHeight: '168px', overflowY: 'auto', marginBottom: '4px' } },
4473
+ list.map((val, idx) => h('div', { key: 'ref-' + idx, style: S.refsRow },
4474
+ h('input', {
4475
+ style: S.refsInput,
4476
+ value: typeof val === 'string' ? val : '',
4477
+ placeholder: t('refsPh'),
4478
+ autoFocus: idx === list.length - 1 && val === '',
4479
+ onKeyDown: (e) => {
4480
+ if (e.key === 'Enter' && list.length < 16) {
4481
+ e.preventDefault();
4482
+ addNodeRef(node);
4483
+ }
4484
+ },
4485
+ onChange: (e) => updateNodeRef(node, idx, e.target.value),
4486
+ }),
4487
+ h('button', {
4488
+ type: 'button',
4489
+ style: S.condBranchDel,
4490
+ title: t('delRefTip'),
4491
+ onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
4492
+ onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
4493
+ onClick: () => removeNodeRef(node, idx),
4494
+ }, '×'),
4495
+ )),
4496
+ ),
4497
+ list.length < 16 && h('button', {
4498
+ type: 'button',
4499
+ style: { ...S.btn, width: '100%', padding: '3px 8px', fontSize: '10px', textAlign: 'center' },
4500
+ onClick: () => addNodeRef(node),
4501
+ }, t('refsAdd')),
4502
+ );
4503
+ };
4504
+
3942
4505
  return h('div', {
3943
4506
  ref: rootElRef,
3944
4507
  style: S.root,
@@ -3950,145 +4513,19 @@ window.__ModuleLoader__.load({
3950
4513
  h('button', { style: S.btn, onClick: () => addNode('lead'), type: 'button' }, t('addLead')),
3951
4514
  h('button', { style: S.btn, onClick: () => addNode('condition'), type: 'button' }, t('addCond')),
3952
4515
  h('span', { style: S.toolSep }),
3953
- h('button', { style: S.btn, onClick: undo, type: 'button', title: t('tipUndo') }, t('undo')),
3954
4516
  h('button', {
3955
4517
  style: enabled && dirty ? S.btnDirty : S.btn,
3956
4518
  onClick: () => pushPlan(enabled),
3957
4519
  type: 'button',
3958
4520
  title: t('tipSync'),
3959
4521
  }, t('sync')),
3960
- h('span', { style: S.toolSep }),
3961
4522
  h('button', {
3962
4523
  style: S.btn,
3963
- onClick: () => fitView(),
3964
- type: 'button',
3965
- title: t('tipLocate'),
3966
- }, t('locate')),
3967
- h('button', {
3968
- style: { ...S.btn, cursor: 'ew-resize', minWidth: '50px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
3969
- onMouseDown: onZoomPillDown,
3970
- onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
3971
- type: 'button',
3972
- title: t('tipResetZoom'),
3973
- }, Math.round(view.k * 100) + '%'),
3974
- h('button', {
3975
- style: direction === 'tb' ? S.btnDirty : S.btn,
3976
4524
  onClick: toggleDirection,
3977
4525
  type: 'button',
3978
4526
  title: t('tipDir'),
3979
4527
  }, direction === 'tb' ? t('dirTB') : t('dirLR')),
3980
4528
  syncNote ? h('span', { style: S.syncNote, title: syncNote }, syncNote) : null,
3981
- h('span', { style: S.toolSep }),
3982
- h('button', {
3983
- style: S.btn,
3984
- onClick: toggleLang,
3985
- type: 'button',
3986
- title: 'Switch language / 切换语言',
3987
- }, t('lang')),
3988
- h('div', { style: S.moreBar },
3989
- h('button', {
3990
- style: S.btn,
3991
- type: 'button',
3992
- title: t('tipMore'),
3993
- onMouseDown: (e) => e.stopPropagation(),
3994
- onClick: (e) => {
3995
- const next = !menuOpen;
3996
- if (next) {
3997
- setPresetOpen(null);
3998
- const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
3999
- const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
4000
- setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
4001
- }
4002
- setMenuOpen(next);
4003
- },
4004
- }, '⋯'),
4005
- menuOpen && h('div', {
4006
- style: {
4007
- ...S.moreMenu,
4008
- left: menuAlign === 'left' ? 0 : 'auto',
4009
- right: menuAlign === 'left' ? 'auto' : 0,
4010
- },
4011
- onMouseDown: (e) => e.stopPropagation(),
4012
- },
4013
- h('div', {
4014
- style: S.moreRow,
4015
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4016
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4017
- onClick: () => { setMenuOpen(false); importFromClipboard(); },
4018
- }, t('importBtn')),
4019
- h('div', {
4020
- style: S.moreRow,
4021
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4022
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4023
- onClick: () => { setMenuOpen(false); exportToClipboard(); },
4024
- }, t('exportBtn')),
4025
- h('div', {
4026
- style: S.moreRow,
4027
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4028
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4029
- onClick: () => { setMenuOpen(false); autoLayout(); },
4030
- }, t('autoLayoutBtn')),
4031
- h('div', {
4032
- style: { ...S.moreRow, color: '#e5534b' },
4033
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4034
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4035
- onClick: () => { clearCanvas(); },
4036
- }, t('clearCanvasBtn')),
4037
- h('div', {
4038
- style: S.moreRow,
4039
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4040
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4041
- onClick: () => {
4042
- const next = nextEffectLevel(fxLevel);
4043
- setFxLevel(next);
4044
- saveEffectLevel(next);
4045
- flash(t('fxLabel') + t('sep') + fxName(next));
4046
- },
4047
- }, t('fxLabel') + t('sep') + fxName(fxLevel)),
4048
- h('div', {
4049
- style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
4050
- title: t('tipMaxParallel'),
4051
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4052
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4053
- onClick: () => {
4054
- const next = nextMaxParallel(maxParallel);
4055
- setMaxParallel(next);
4056
- maxParallelRef.current = next;
4057
- saveMaxParallel(next);
4058
- if (enabled) pushPlan(true, undefined, undefined, next);
4059
- else flash(t('maxParallelLabel') + t('sep') + next);
4060
- },
4061
- },
4062
- h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
4063
- h('span', {
4064
- title: t('tipMaxParallel'),
4065
- style: {
4066
- display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
4067
- width: '14px', height: '14px', borderRadius: '50%',
4068
- border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
4069
- color: maxParallel > 4 ? '#d29922' : C.dim,
4070
- fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
4071
- },
4072
- }, '!'),
4073
- ),
4074
- h('div', {
4075
- style: S.moreRow,
4076
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4077
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4078
- onClick: () => {
4079
- const next = !cutMode;
4080
- setCutMode(next);
4081
- saveCutMode(next);
4082
- },
4083
- }, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
4084
- h('div', {
4085
- style: S.moreRow,
4086
- onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4087
- onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4088
- onClick: () => { setMenuOpen(false); setHelpOpen(true); },
4089
- }, t('help')),
4090
- ),
4091
- ),
4092
4529
  h('div', { style: S.presetBar },
4093
4530
  (() => {
4094
4531
  const feedback = status || (enabled ? (dirty ? t('unsaved') : t('synced')) : '');
@@ -4102,6 +4539,7 @@ window.__ModuleLoader__.load({
4102
4539
  const next = presetOpen === 'menu' ? null : 'menu';
4103
4540
  if (next) {
4104
4541
  setMenuOpen(false);
4542
+ setCtxMenu(null);
4105
4543
  const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
4106
4544
  const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
4107
4545
  setPresetAlign(dropdownAlign(btnRect, rootRect, 248));
@@ -4170,9 +4608,145 @@ window.__ModuleLoader__.load({
4170
4608
  }, h('span', { style: S.presetRowText, title: tpl.name }, tpl.name))),
4171
4609
  );
4172
4610
  })(),
4611
+ h('div', { style: S.moreBar },
4612
+ h('button', {
4613
+ style: S.btn,
4614
+ type: 'button',
4615
+ title: t('tipMore'),
4616
+ onMouseDown: (e) => e.stopPropagation(),
4617
+ onClick: (e) => {
4618
+ const next = !menuOpen;
4619
+ if (next) {
4620
+ setPresetOpen(null);
4621
+ setCtxMenu(null);
4622
+ const rootRect = rootElRef.current && rootElRef.current.getBoundingClientRect();
4623
+ const btnRect = e.currentTarget && e.currentTarget.getBoundingClientRect();
4624
+ setMenuAlign(dropdownAlign(btnRect, rootRect, 204));
4625
+ }
4626
+ setMenuOpen(next);
4627
+ },
4628
+ }, '⋯'),
4629
+ menuOpen && h('div', {
4630
+ style: {
4631
+ ...S.moreMenu,
4632
+ left: menuAlign === 'left' ? 0 : 'auto',
4633
+ right: menuAlign === 'left' ? 'auto' : 0,
4634
+ },
4635
+ onMouseDown: (e) => e.stopPropagation(),
4636
+ },
4637
+ h('div', {
4638
+ style: S.moreRow,
4639
+ title: t('tipUndo'),
4640
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4641
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4642
+ onClick: () => { setMenuOpen(false); undo(); },
4643
+ }, t('undo')),
4644
+ h('div', {
4645
+ style: S.moreRow,
4646
+ title: t('tipLocate'),
4647
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4648
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4649
+ onClick: () => { setMenuOpen(false); fitView(); },
4650
+ }, t('locate')),
4651
+ h('div', { style: S.ctxDivider }),
4652
+ h('div', {
4653
+ style: S.moreRow,
4654
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4655
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4656
+ onClick: () => { setMenuOpen(false); importFromClipboard(); },
4657
+ }, t('importBtn')),
4658
+ h('div', {
4659
+ style: S.moreRow,
4660
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4661
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4662
+ onClick: () => { setMenuOpen(false); exportToClipboard(); },
4663
+ }, t('exportBtn')),
4664
+ h('div', {
4665
+ style: S.moreRow,
4666
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4667
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4668
+ onClick: () => { setMenuOpen(false); autoLayout(); },
4669
+ }, t('autoLayoutBtn')),
4670
+ h('div', {
4671
+ style: { ...S.moreRow, color: '#e5534b' },
4672
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4673
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4674
+ onClick: () => { clearCanvas(); },
4675
+ }, t('clearCanvasBtn')),
4676
+ h('div', { style: S.ctxDivider }),
4677
+ h('div', {
4678
+ style: S.moreRow,
4679
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4680
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4681
+ onClick: () => {
4682
+ const next = nextEffectLevel(fxLevel);
4683
+ setFxLevel(next);
4684
+ saveEffectLevel(next);
4685
+ flash(t('fxLabel') + t('sep') + fxName(next));
4686
+ },
4687
+ }, t('fxLabel') + t('sep') + fxName(fxLevel)),
4688
+ h('div', {
4689
+ style: { ...S.moreRow, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' },
4690
+ title: t('tipMaxParallel'),
4691
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4692
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4693
+ onClick: () => {
4694
+ const next = nextMaxParallel(maxParallel);
4695
+ setMaxParallel(next);
4696
+ maxParallelRef.current = next;
4697
+ saveMaxParallel(next);
4698
+ if (enabled) pushPlan(true, undefined, undefined, next);
4699
+ else flash(t('maxParallelLabel') + t('sep') + next);
4700
+ },
4701
+ },
4702
+ h('span', null, t('maxParallelLabel') + t('sep') + maxParallel),
4703
+ h('span', {
4704
+ title: t('tipMaxParallel'),
4705
+ style: {
4706
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
4707
+ width: '14px', height: '14px', borderRadius: '50%',
4708
+ border: '1px solid ' + (maxParallel > 4 ? '#d29922' : C.dim),
4709
+ color: maxParallel > 4 ? '#d29922' : C.dim,
4710
+ fontSize: '10px', fontWeight: 700, lineHeight: '12px', flex: '0 0 auto',
4711
+ },
4712
+ }, '!'),
4713
+ ),
4714
+ h('div', {
4715
+ style: S.moreRow,
4716
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4717
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4718
+ onClick: () => {
4719
+ const next = !cutMode;
4720
+ setCutMode(next);
4721
+ saveCutMode(next);
4722
+ },
4723
+ }, t('cutLinks') + t('sep') + (cutMode ? t('on') : t('off'))),
4724
+ h('div', {
4725
+ style: S.moreRow,
4726
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4727
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4728
+ onClick: () => { toggleLang(); },
4729
+ }, t('ctxLangToggle') + t('sep') + (lang === 'zh' ? '中文' : 'EN')),
4730
+ h('div', {
4731
+ style: S.moreRow,
4732
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4733
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4734
+ onClick: () => { setMenuOpen(false); setRecordingAction(null); setShortcutsOpen(true); },
4735
+ }, t('shortcutsMenu')),
4736
+ h('div', {
4737
+ style: S.moreRow,
4738
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4739
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4740
+ onClick: () => { setMenuOpen(false); setHelpOpen(true); },
4741
+ }, t('help')),
4742
+ ),
4743
+ ),
4173
4744
  ),
4174
4745
  ),
4175
- helpOpen && h('div', { style: S.helpOverlay, onMouseDown: (e) => e.stopPropagation() },
4746
+ helpOpen && h('div', {
4747
+ style: S.helpOverlay,
4748
+ onMouseDown: (e) => { e.stopPropagation(); if (e.target === e.currentTarget) setHelpOpen(false); },
4749
+ },
4176
4750
  h('div', { style: S.helpCard },
4177
4751
  h('div', { style: S.helpHead },
4178
4752
  h('span', { style: S.helpTitle }, t('helpTitle')),
@@ -4181,10 +4755,92 @@ window.__ModuleLoader__.load({
4181
4755
  h('div', { style: S.helpBody }, t('helpBody').split('\n').map((line, i) => h('div', { key: i, style: S.helpLine }, line))),
4182
4756
  ),
4183
4757
  ),
4758
+ shortcutsOpen && (() => {
4759
+ const actionLabels = {
4760
+ addNode: t('scAddNode'),
4761
+ duplicate: t('scDuplicate'),
4762
+ delete: t('scDelete'),
4763
+ undo: t('scUndo'),
4764
+ fitView: t('scFitView'),
4765
+ autoLayout: t('scAutoLayout'),
4766
+ toggleDir: t('scToggleDir'),
4767
+ };
4768
+ return h('div', {
4769
+ style: S.helpOverlay,
4770
+ onMouseDown: (e) => {
4771
+ e.stopPropagation();
4772
+ if (e.target === e.currentTarget) {
4773
+ setRecordingAction(null);
4774
+ setShortcutsOpen(false);
4775
+ }
4776
+ },
4777
+ },
4778
+ h('div', { style: { ...S.helpCard, maxWidth: '360px' } },
4779
+ h('div', { style: S.helpHead },
4780
+ h('span', { style: S.helpTitle }, t('shortcutsTitle')),
4781
+ h('button', {
4782
+ style: S.btn,
4783
+ type: 'button',
4784
+ onClick: () => {
4785
+ const resetMap = { ...DEFAULT_SHORTCUTS };
4786
+ shortcutsRef.current = resetMap;
4787
+ saveShortcuts(resetMap);
4788
+ setShortcuts(resetMap);
4789
+ setRecordingAction(null);
4790
+ flash(t('shortcutsResetOk'));
4791
+ },
4792
+ }, t('shortcutsReset')),
4793
+ h('button', {
4794
+ style: S.btn,
4795
+ type: 'button',
4796
+ onClick: () => { setRecordingAction(null); setShortcutsOpen(false); },
4797
+ }, t('close')),
4798
+ ),
4799
+ h('div', { style: { fontSize: '10px', color: C.dim, marginBottom: '8px', lineHeight: '1.45' } }, t('shortcutsHint')),
4800
+ SHORTCUT_ORDER.map((actionId, idx) => {
4801
+ const binding = shortcuts[actionId] || '';
4802
+ const isRec = recordingAction === actionId;
4803
+ return h('div', {
4804
+ key: actionId,
4805
+ style: idx === SHORTCUT_ORDER.length - 1 ? { ...S.shortcutRow, borderBottom: 'none' } : S.shortcutRow,
4806
+ },
4807
+ h('span', null, actionLabels[actionId] || actionId),
4808
+ h('div', { style: { display: 'inline-flex', alignItems: 'center', gap: '4px' } },
4809
+ h('button', {
4810
+ type: 'button',
4811
+ style: isRec ? { ...S.shortcutKeyBtn, ...S.shortcutKeyRec } : (binding ? S.shortcutKeyBtn : { ...S.shortcutKeyBtn, color: C.dim }),
4812
+ onClick: () => setRecordingAction(isRec ? null : actionId),
4813
+ }, isRec ? t('shortcutsPress') : (binding || t('shortcutsUnset'))),
4814
+ binding
4815
+ ? h('button', {
4816
+ type: 'button',
4817
+ style: S.condBranchDel,
4818
+ title: t('del'),
4819
+ onMouseEnter: (e) => { e.currentTarget.style.color = '#e5534b'; },
4820
+ onMouseLeave: (e) => { e.currentTarget.style.color = C.dim; },
4821
+ onClick: () => {
4822
+ const { next } = applyShortcutBinding(shortcutsRef.current, actionId, '');
4823
+ shortcutsRef.current = next;
4824
+ saveShortcuts(next);
4825
+ setShortcuts(next);
4826
+ if (recordingAction === actionId) setRecordingAction(null);
4827
+ },
4828
+ }, '×')
4829
+ : h('span', { style: S.condBranchDelSpacer }),
4830
+ ),
4831
+ );
4832
+ }),
4833
+ ),
4834
+ );
4835
+ })(),
4184
4836
  h('div', {
4185
4837
  ref: canvasWrapRef,
4186
4838
  style: S.canvasWrap,
4187
4839
  onMouseMove: (e) => { lastMouseRef.current = { clientX: e.clientX, clientY: e.clientY }; },
4840
+ onContextMenu: (e) => {
4841
+ const tag = e.target && e.target.tagName;
4842
+ if (tag !== 'INPUT' && tag !== 'TEXTAREA') e.preventDefault();
4843
+ },
4188
4844
  },
4189
4845
  h('button', {
4190
4846
  style: enabled
@@ -4216,7 +4872,7 @@ window.__ModuleLoader__.load({
4216
4872
  const lf = addMenu.linkFrom || null;
4217
4873
  const srcNode = lf && lf.fromId ? nodeById.get(lf.fromId) : null;
4218
4874
  const compat = lf ? compatibleTargetsForWire(srcNode, lf.type) : { agent: true, lead: true, condition: true, leadBlockedReason: '' };
4219
- return h('div', {
4875
+ return h('div', {
4220
4876
  style: { ...S.addMenu, left: addMenu.sx + 'px', top: addMenu.sy + 'px' },
4221
4877
  onMouseDown: (e) => e.stopPropagation(),
4222
4878
  },
@@ -4242,6 +4898,100 @@ window.__ModuleLoader__.load({
4242
4898
  }, h('span', null, t('addCond')), h('span', { style: S.addMenuHint }, '3')),
4243
4899
  );
4244
4900
  })(),
4901
+ ctxMenu && (() => {
4902
+ const menuRow = (key, label, onClick, opts) => {
4903
+ const danger = opts && opts.danger;
4904
+ const hint = opts && opts.hint;
4905
+ return h('div', {
4906
+ key,
4907
+ style: danger ? { ...S.addMenuRow, color: '#e5534b' } : S.addMenuRow,
4908
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4909
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4910
+ onClick,
4911
+ }, h('span', null, label), hint ? h('span', { style: S.addMenuHint }, hint) : null);
4912
+ };
4913
+ if (ctxMenu.kind === 'node') {
4914
+ const target = nodeById.get(ctxMenu.nodeId);
4915
+ if (!target) return null;
4916
+ const multiSel = selectedIds.length > 1 && selectedSet.has(target.id);
4917
+ const nonLeadCount = (multiSel ? selectedIds : [target.id]).filter((id) => id !== 'lead').length;
4918
+ const suffix = nonLeadCount > 1 ? ' ×' + nonLeadCount : '';
4919
+ const latestRun = target.kind !== 'lead' ? runsById[target.id] : null;
4920
+ return h('div', {
4921
+ style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
4922
+ onMouseDown: (e) => e.stopPropagation(),
4923
+ onContextMenu: (e) => e.preventDefault(),
4924
+ },
4925
+ h('div', { style: S.addMenuHead }, t('ctxNodeTitle')),
4926
+ menuRow('edit', t('ctxEditText'), () => { setCtxMenu(null); setRoleEditFor(target.id); }),
4927
+ menuRow('refs', t('ctxManageRefs'), () => { setCtxMenu(null); setRefsEditFor(target.id); }),
4928
+ latestRun && menuRow('chat', t('ctxOpenChat'), () => { setCtxMenu(null); openNodeSession(target); }),
4929
+ nonLeadCount > 0 && h('div', { style: S.ctxDivider }),
4930
+ nonLeadCount > 0 && menuRow('dup', t('ctxDup') + suffix, () => { setCtxMenu(null); duplicateSelected(); }, { hint: shortcuts.duplicate || '' }),
4931
+ nonLeadCount > 0 && menuRow('del', t('ctxDelNode') + suffix, () => {
4932
+ setCtxMenu(null);
4933
+ if (multiSel) deleteSelected();
4934
+ else deleteNode(target.id);
4935
+ }, { danger: true, hint: shortcuts.delete === 'Delete' ? 'Del' : (shortcuts.delete || '') }),
4936
+ );
4937
+ }
4938
+ if (ctxMenu.kind === 'edge') {
4939
+ const targetEdge = edges.find((ed) => ed.id === ctxMenu.edgeId);
4940
+ if (!targetEdge) return null;
4941
+ return h('div', {
4942
+ style: { ...S.addMenu, minWidth: '172px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
4943
+ onMouseDown: (e) => e.stopPropagation(),
4944
+ onContextMenu: (e) => e.preventDefault(),
4945
+ },
4946
+ h('div', { style: S.addMenuHead }, t('ctxEdgeTitle')),
4947
+ menuRow('ins-agent', t('ctxInsertAgent'), () => insertNodeOnEdge(targetEdge.id, 'agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
4948
+ menuRow('ins-cond', t('ctxInsertCond'), () => insertNodeOnEdge(targetEdge.id, 'condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
4949
+ h('div', { style: S.ctxDivider }),
4950
+ menuRow('del-edge', t('ctxDelEdge'), () => deleteEdgeById(targetEdge.id), { danger: true }),
4951
+ );
4952
+ }
4953
+ return h('div', {
4954
+ style: { ...S.addMenu, minWidth: '176px', left: ctxMenu.sx + 'px', top: ctxMenu.sy + 'px' },
4955
+ onMouseDown: (e) => e.stopPropagation(),
4956
+ onContextMenu: (e) => e.preventDefault(),
4957
+ },
4958
+ h('div', { style: S.addMenuHead }, t('ctxCanvasTitle')),
4959
+ menuRow('add-agent', t('addAgent'), () => addNode('agent', { x: ctxMenu.wx, y: ctxMenu.wy })),
4960
+ menuRow('add-lead', t('addLead'), () => addNode('lead', { x: ctxMenu.wx, y: ctxMenu.wy })),
4961
+ menuRow('add-cond', t('addCond'), () => addNode('condition', { x: ctxMenu.wx, y: ctxMenu.wy })),
4962
+ h('div', { style: S.ctxDivider }),
4963
+ menuRow('undo', t('undo'), () => { setCtxMenu(null); undo(); }, { hint: shortcuts.undo || '' }),
4964
+ menuRow('layout', t('autoLayoutBtn'), () => { setCtxMenu(null); autoLayout(); }, { hint: shortcuts.autoLayout || '' }),
4965
+ menuRow('dir', direction === 'tb' ? t('dirLR') : t('dirTB'), () => { setCtxMenu(null); toggleDirection(); }, { hint: shortcuts.toggleDir || '' }),
4966
+ menuRow('fit', t('locate'), () => { setCtxMenu(null); fitView(); }, { hint: shortcuts.fitView || '' }),
4967
+ h('div', { style: S.ctxDivider }),
4968
+ menuRow('imp', t('importBtn'), () => { setCtxMenu(null); importFromClipboard(); }),
4969
+ menuRow('clr', t('clearCanvasBtn'), () => { setCtxMenu(null); clearCanvas(); }, { danger: true }),
4970
+ );
4971
+ })(),
4972
+ h('div', {
4973
+ style: S.floatZoomBar,
4974
+ onMouseDown: (e) => e.stopPropagation(),
4975
+ },
4976
+ h('button', {
4977
+ style: S.floatZoomBtn,
4978
+ type: 'button',
4979
+ title: t('tipLocate'),
4980
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4981
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4982
+ onClick: () => fitView(),
4983
+ }, '⊡'),
4984
+ h('span', { style: { width: '1px', height: '12px', background: C.border, opacity: 0.7 } }),
4985
+ h('button', {
4986
+ style: { ...S.floatZoomBtn, cursor: 'ew-resize', minWidth: '42px', textAlign: 'center', fontVariantNumeric: 'tabular-nums' },
4987
+ type: 'button',
4988
+ title: t('tipResetZoom'),
4989
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
4990
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent'; },
4991
+ onMouseDown: onZoomPillDown,
4992
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); focusLead(1); } },
4993
+ }, Math.round(view.k * 100) + '%'),
4994
+ ),
4245
4995
  h('div', {
4246
4996
  ref: canvasElRef,
4247
4997
  style: {
@@ -4334,6 +5084,10 @@ window.__ModuleLoader__.load({
4334
5084
  const isPruned = enabled && prunedSet.has(node.id);
4335
5085
  const condDecision = isCondKind ? (decisionsById[node.id] || null) : null;
4336
5086
  const verdictInfo = condDecision ? conditionVerdictSummary(condDecision, lang) : null;
5087
+ const hasOpenPopover = decisionViewFor === node.id
5088
+ || refsEditFor === node.id
5089
+ || roleEditFor === node.id
5090
+ || (typeof roleEditFor === 'string' && roleEditFor.includes(':' + node.id + ':'));
4337
5091
  return h('div', {
4338
5092
  key: node.id,
4339
5093
  'data-node': node.id,
@@ -4346,10 +5100,11 @@ window.__ModuleLoader__.load({
4346
5100
  ...(isLeadKind ? S.leadNode : null),
4347
5101
  ...(isInactive || isPruned ? S.orphanNode : null),
4348
5102
  ...(stateStyle || null),
4349
- ...(decisionViewFor === node.id ? { zIndex: 40 } : null),
5103
+ ...(hasOpenPopover ? { zIndex: 40 } : null),
4350
5104
  },
4351
5105
  title: isPruned ? t('tipPruned') : (isOrphan ? t('orphanTip') : (isSoloLead ? t('tipSoloLead') : (isDeadEnd ? t('tipDeadEnd') : undefined))),
4352
5106
  onMouseDown: (e) => onNodeDown(e, node.id),
5107
+ onContextMenu: (e) => onNodeContextMenu(e, node),
4353
5108
  },
4354
5109
  h('div', {
4355
5110
  className: (isRunning || isLeadReady) && fxLevel === 'vivid' ? 'dsh-wc-topbar-vivid' : undefined,
@@ -4462,7 +5217,7 @@ window.__ModuleLoader__.load({
4462
5217
  }, enabled ? glyph : null, label, ' ↗');
4463
5218
  }
4464
5219
  if (!enabled) return null;
4465
- return h('div', {
5220
+ return h('div', {
4466
5221
  style: {
4467
5222
  ...S.statusChip,
4468
5223
  bottom: (direction === 'tb' && !isCondKind) ? '28px' : '5px',
@@ -4722,6 +5477,8 @@ window.__ModuleLoader__.load({
4722
5477
  style: { maxHeight: '140px', overflowY: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word', color: C.text, fontSize: '11px' },
4723
5478
  }, (condDecision.reason && String(condDecision.reason).trim()) || t('verdictNoReason')),
4724
5479
  ),
5480
+ refsControlBtn(node),
5481
+ refsPopoverEl(node),
4725
5482
  renderBand(node),
4726
5483
  );
4727
5484
  }),
@@ -4760,7 +5517,7 @@ window.__ModuleLoader__.load({
4760
5517
  try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
4761
5518
  }
4762
5519
  },
4763
- __test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState, outputSocketX, inputSocketPos, outputSocketPos },
5520
+ __test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, nextMaxParallel, dropdownAlign, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, nodeHeight, conditionBranchesForUI, distanceToEdge, edgeCurve, compatibleTargetsForWire, conditionVerdictSummary, entryRunButtonState, outputSocketX, inputSocketPos, outputSocketPos, normalizeRefsUI, clampMenuPos, cloneSelection, DEFAULT_SHORTCUTS, normalizeShortcut, formatShortcutFromEvent, matchesShortcut, applyShortcutBinding },
4764
5521
  };
4765
5522
  },
4766
5523
  });