dsh-workflow-canvas 0.2.4 → 1.0.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
@@ -128,6 +128,7 @@ window.__ModuleLoader__.load({
128
128
  savedPreset: '已保存预设', saveFailed: '保存失败(存储不可用)',
129
129
  loadedPreset: '已载入预设', invalidPreset: '预设内容无效', deletedPreset: '已删除预设',
130
130
  syncFailed: '同步失败', upToDate: '已是最新', syncedToHost: '已同步到 Host',
131
+ syncedWithStdWarn: '已同步(含可写/命令节点,请确认主对话权限已放开)',
131
132
  cannotOpen: '无法打开会话', undoDone: '已撤销', undoNone: '没有可撤销的操作',
132
133
  leadLocked: '入口 Lead 不能删除', modelsMissing: '模型列表未加载',
133
134
  tipLead: 'Lead 步骤在对话里执行,画布不追踪其状态',
@@ -173,6 +174,7 @@ window.__ModuleLoader__.load({
173
174
  newBlankCanvas: '+ 新建空白画布',
174
175
  clearedCanvas: '已清空画布(可用 ↶ 撤销)',
175
176
  cycleBlocked: '不能形成环,已阻止连线',
177
+ leadToLeadBlocked: 'Lead 节点不能直接连到另一个 Lead,请在中间放入子代理',
176
178
  builtinTemplates: '内置示例模板',
177
179
  myPresets: '我的预设',
178
180
  duplicatedNodes: '已复制节点',
@@ -184,7 +186,9 @@ window.__ModuleLoader__.load({
184
186
  fxVivid: '炫酷',
185
187
  tipLeadReady: '上游节点已全部完成,正等待在对话里拍板继续',
186
188
  stDeadEnd: '无出边',
187
- tipDeadEnd: '该子代理节点没有下游连线:若需把产出交给后续节点或终审 Lead,请从右侧端口连出',
189
+ tipDeadEnd: '该子代理没有下游连线,运行时不生效;请连入下游节点或终审 Lead',
190
+ stSoloLead: '未接子代理',
191
+ tipSoloLead: '该 Lead 仅串联了其他 Lead,未连入任何子代理,运行时不生效',
188
192
  singleModelHint: '当前仅 1 个可用模型,暂无其它备用路由',
189
193
  importNone: '剪贴板里没有可识别的画布数据',
190
194
  importBad: '画布数据格式不对',
@@ -192,7 +196,12 @@ window.__ModuleLoader__.load({
192
196
  tipUndo: '撤销上一步结构改动', tipSave: '把当前画布保存为预设',
193
197
  tipPresets: '载入已保存的预设', tipModel: '推理等级(默认 = 该模型声明的 defaultEffort)',
194
198
  tipMemory: '记忆:复用这个节点上一次的会话(跨运行及重启后可恢复)',
195
- tipPreset: '能力范围(点一下切换):standard = 全部工具(读写文件、跑命令、子代理、工作流、网页、办公);minimal = 只读思考(文件读写关闭,没有子代理/工作流/网页)',
199
+ memLatest: '最新',
200
+ memLatestOpt: '自动(最新记忆)',
201
+ memRunOpt: '第 {n} 次会话',
202
+ memEmpty: '运行后这里会列出可选的历史会话',
203
+ tipMemoryPick: '选择要续接的历史子会话(默认自动沿用最新记忆)',
204
+ tipPreset: '能力范围(点一下切换,受主对话权限上限约束):standard = 全部工具(读写文件、跑命令、子代理、工作流、网页、办公);minimal = 只读思考(文件读写关闭,没有子代理/工作流/网页)',
196
205
  tipFallback: '失败重试:该节点出错时自动换一个模型再跑一次',
197
206
  tipStructured: 'JSON 输出:要求该节点返回 JSON 对象,structured 连线会把结果作为 JSON 传给下游',
198
207
  lang: 'ZH',
@@ -229,6 +238,7 @@ window.__ModuleLoader__.load({
229
238
  savedPreset: 'Saved preset', saveFailed: 'Save failed (storage unavailable)',
230
239
  loadedPreset: 'Loaded preset', invalidPreset: 'Preset content is invalid', deletedPreset: 'Deleted preset',
231
240
  syncFailed: 'Sync failed', upToDate: 'Already up to date', syncedToHost: 'Synced to host',
241
+ syncedWithStdWarn: 'Synced (has write/tool nodes — check main chat permission mode)',
232
242
  cannotOpen: 'Cannot open the session', undoDone: 'Undone', undoNone: 'Nothing to undo',
233
243
  leadLocked: 'The entry Lead cannot be deleted', modelsMissing: 'Model list is not loaded',
234
244
  tipLead: 'Lead steps run in the chat; the canvas does not track them',
@@ -274,6 +284,7 @@ window.__ModuleLoader__.load({
274
284
  newBlankCanvas: '+ New blank canvas',
275
285
  clearedCanvas: 'Canvas cleared (use Undo to restore)',
276
286
  cycleBlocked: 'Cannot create a cycle',
287
+ leadToLeadBlocked: 'Cannot link a Lead directly to another Lead; place a subagent in between',
277
288
  builtinTemplates: 'Starter templates',
278
289
  myPresets: 'Saved presets',
279
290
  duplicatedNodes: 'Duplicated nodes',
@@ -285,7 +296,9 @@ window.__ModuleLoader__.load({
285
296
  fxVivid: 'Vivid',
286
297
  tipLeadReady: 'Upstream steps are done; waiting for Lead in chat',
287
298
  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',
299
+ tipDeadEnd: 'This subagent has no outgoing link and is skipped at run time; wire it into a downstream node or Lead',
300
+ stSoloLead: 'Needs agent',
301
+ tipSoloLead: 'This Lead only chains from another Lead with no subagent upstream, so it is skipped at run time',
289
302
  singleModelHint: 'Only 1 model available — no alternate fallback route',
290
303
  importNone: 'No canvas data found in the clipboard',
291
304
  importBad: 'Canvas data is malformed',
@@ -293,7 +306,12 @@ window.__ModuleLoader__.load({
293
306
  tipUndo: 'Undo the last structural change', tipSave: 'Save this canvas as a preset',
294
307
  tipPresets: 'Load a saved preset', tipModel: 'Reasoning effort (default = the model\'s defaultEffort)',
295
308
  tipMemory: 'Memory: reuse this node\'s previous session (persisted across runs and restarts)',
296
- tipPreset: 'Capability (click to toggle): standard = all tools (files, shells, subagents, workflow, web, office); minimal = read-only thinking (no file writes, no subagents/workflow/web)',
309
+ memLatest: 'Latest',
310
+ memLatestOpt: 'Auto (latest)',
311
+ memRunOpt: 'Run #{n}',
312
+ memEmpty: 'Past runs appear here after running',
313
+ tipMemoryPick: 'Pick which past child session to resume (defaults to latest)',
314
+ tipPreset: 'Capability (click to toggle; bounded by the main chat permission mode): standard = all tools (files, shells, subagents, workflow, web, office); minimal = read-only thinking (no file writes, no subagents/workflow/web)',
297
315
  tipFallback: 'Retry: when this node fails, rerun it once on another model',
298
316
  tipStructured: 'JSON output: require an object result; structured links pass it downstream as JSON',
299
317
  lang: 'EN',
@@ -725,132 +743,59 @@ window.__ModuleLoader__.load({
725
743
  return out.length === nodes.length ? out : null;
726
744
  }
727
745
 
728
- function varOf(id) {
729
- return 'n_' + String(id).replace(/[^a-zA-Z0-9_]/g, '_');
730
- }
731
-
732
- function buildWorkflowScript(nodes, edges) {
733
- const entry = nodes.find((n) => n.id === 'lead');
734
- if (!entry) return { error: '缺少入口 Lead 节点' };
735
- const rest = nodes.filter((n) => n.id !== 'lead');
736
- if (!rest.length) return { error: '画布上还没有可执行的节点' };
737
- const task = String(entry.task || '').trim();
738
- if (!task) return { error: '请先在 Lead 节点填写「本次任务」' };
739
-
740
- const byIdAll = new Map(rest.map((n) => [n.id, n]));
741
-
742
- const reachable = new Set([entry.id]);
743
- let grew = true;
744
- while (grew) {
745
- grew = false;
746
- for (const e of edges) {
747
- if (reachable.has(e.from) && !reachable.has(e.to)) { reachable.add(e.to); grew = true; }
748
- }
749
- }
750
- const orphan = rest.filter((n) => !reachable.has(n.id));
751
- if (orphan.length) {
752
- return { error: '这些节点没有从入口 Lead 连过来:' + orphan.map((n) => n.label).join('、') };
753
- }
754
-
755
- const dataEdgesAll = edges.filter((e) => e.from !== entry.id && byIdAll.has(e.from) && byIdAll.has(e.to));
756
-
757
- // Lead-kind nodes are executed by the conversation itself, which can only
758
- // happen after the script returns — so they must be terminal.
759
- const leadNodes = rest.filter((n) => n.kind === 'lead');
760
- for (const ln of leadNodes) {
761
- if (dataEdgesAll.some((e) => e.from === ln.id)) {
762
- return {
763
- error: '中间 Lead 节点暂不支持(「' + ln.label + '」后面还有步骤)。'
764
- + '把中间这一步换成子代理,或把它移到流程末尾。',
765
- };
766
- }
767
- }
768
-
769
- const agentNodes = rest.filter((n) => n.kind !== 'lead');
770
- if (!agentNodes.length) return { error: '需要至少一个子代理节点来执行' };
771
-
772
- const byId = new Map(agentNodes.map((n) => [n.id, n]));
773
- const dataEdges = dataEdgesAll.filter((e) => byId.has(e.from) && byId.has(e.to));
774
- const order = topoOrder(agentNodes, dataEdges);
775
- if (!order) return { error: '存在环,无法生成有向无环图的脚本' };
776
-
777
- const upstream = new Map(agentNodes.map((n) => [n.id, []]));
778
- for (const e of dataEdges) upstream.get(e.to).push(e);
779
- const hasDownstream = new Set(dataEdges.map((e) => e.from));
780
-
781
- // Hand back everything a lead step consumes, plus every terminal agent.
782
- const delivered = [];
783
- const deliver = (id) => { if (byId.has(id) && !delivered.includes(id)) delivered.push(id); };
784
- for (const ln of leadNodes) {
785
- for (const e of dataEdgesAll) if (e.to === ln.id) deliver(e.from);
746
+ /** Ids reachable from the entry Lead via O(V + E) BFS; every other node is skipped at run time. */
747
+ function reachableFrom(nodes, edges) {
748
+ const adj = new Map();
749
+ for (const e of edges || []) {
750
+ if (!e || !e.from || !e.to) continue;
751
+ if (!adj.has(e.from)) adj.set(e.from, []);
752
+ adj.get(e.from).push(e.to);
786
753
  }
787
- for (const n of agentNodes) if (!hasDownstream.has(n.id)) deliver(n.id);
788
-
789
- const lines = [];
790
- lines.push('// meta: ' + JSON.stringify({ name: 'workflow-canvas', description: 'Canvas-generated agent DAG', phases: [{ title: 'run' }] }));
791
- for (const id of order) {
792
- const node = byId.get(id);
793
- const ups = upstream.get(id);
794
- const isRoot = ups.length === 0;
795
- const upsLabels = ups.map((e) => (byId.get(e.from) || {}).label).filter(Boolean);
796
- const downs = dataEdgesAll.filter((e) => e.from === id).map((e) => (byIdAll.get(e.to) || {}).label).filter(Boolean);
797
- const head = [];
798
- head.push('【工作流节点】你在一个多步工作流里负责「' + node.label + '」这一步(子代理)。');
799
- if (isRoot) head.push('【总任务】' + task);
800
- head.push('【职责】' + (node.role || node.label || id));
801
- if (upsLabels.length) head.push('【上游】' + upsLabels.join('、') + ' 已交付结果给你(见下文)。');
802
- head.push('【下游】' + (downs.length ? downs.join('、') + ' 会使用你的输出。' : '你是终点,结果会直接交付给用户。'));
803
- head.push('【要求】只完成你这一步;输出要能被下游直接使用,不要重复上游已完成的工作。');
804
- const pieces = [JSON.stringify(head.join('\n') + '\n')];
805
- for (const e of ups) {
806
- const from = byId.get(e.from);
807
- pieces.push(JSON.stringify('\n## 来自【' + from.label + '】(' + (e.type || 'prompt') + ')\n'));
808
- pieces.push(varOf(e.from));
754
+ const set = new Set(['lead']);
755
+ const queue = ['lead'];
756
+ for (let i = 0; i < queue.length; i += 1) {
757
+ const cur = queue[i];
758
+ for (const next of adj.get(cur) || []) {
759
+ if (!set.has(next)) { set.add(next); queue.push(next); }
809
760
  }
810
- // The label carries the canvas node id so the client can match the
811
- // spawned subagent session back to its node through the catalog.
812
- const opts = ["label: " + JSON.stringify((node.label || id) + '#' + id), "phase: 'run'"];
813
- if (node.provider) opts.push('provider: ' + JSON.stringify(node.provider));
814
- if (node.model) opts.push('model: ' + JSON.stringify(node.model));
815
- lines.push('const ' + varOf(id) + ' = await agent(' + pieces.join(' + ') + ', { ' + opts.join(', ') + ' });');
816
761
  }
817
- lines.push('// 交付给 Lead:' + delivered.map((id) => byId.get(id).label).join('、'));
818
- const rets = delivered.map((id) => JSON.stringify(byId.get(id).label) + ': ' + varOf(id));
819
- lines.push('return { ' + rets.join(', ') + ' };');
820
-
821
- // These run in the conversation after the script returns.
822
- const leadSteps = leadNodes.map((ln) => ({
823
- label: ln.label,
824
- role: ln.role || ln.label,
825
- needs: dataEdgesAll.filter((e) => e.to === ln.id).map((e) => (byIdAll.get(e.from) || {}).label).filter(Boolean),
826
- }));
827
-
828
- return { script: lines.join('\n'), leadSteps };
762
+ return set;
829
763
  }
830
764
 
831
- /** Ids reachable from the entry Lead; every other node is skipped at run time. */
832
- function reachableFrom(nodes, edges) {
833
- const set = new Set(['lead']);
834
- let grew = true;
835
- while (grew) {
836
- grew = false;
837
- for (const e of edges) {
838
- if (set.has(e.from) && !set.has(e.to)) { set.add(e.to); grew = true; }
839
- }
765
+ /**
766
+ * Reachable non-entry Lead nodes that have zero reachable subagent upstream
767
+ * (chained solely from another Lead). Rendered dashed and skipped at run time;
768
+ * connecting any subagent into them makes them active immediately.
769
+ */
770
+ function soloLeadNodeIds(nodes, edges) {
771
+ const list = Array.isArray(nodes) ? nodes : [];
772
+ const linkList = Array.isArray(edges) ? edges : [];
773
+ const reachable = reachableFrom(list, linkList);
774
+ const byId = new Map(list.map((n) => [n.id, n]));
775
+ const out = new Set();
776
+ for (const n of list) {
777
+ if (n.kind !== 'lead' || n.id === 'lead' || !reachable.has(n.id)) continue;
778
+ const hasAgentUp = linkList.some((e) => {
779
+ if (!e || e.to !== n.id || !reachable.has(e.from) || e.from === 'lead') return false;
780
+ const src = byId.get(e.from);
781
+ return Boolean(src && src.kind !== 'lead');
782
+ });
783
+ if (!hasAgentUp) out.add(n.id);
840
784
  }
841
- return set;
785
+ return out;
842
786
  }
843
787
 
844
788
  /**
845
789
  * 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).
790
+ * one active downstream Lead that is NOT an ancestor of that agent (dangling
791
+ * branch whose output is never consumed). Rendered dashed and skipped at run time.
848
792
  */
849
793
  function deadEndNodeIds(nodes, edges) {
850
794
  const list = Array.isArray(nodes) ? nodes : [];
851
795
  const linkList = Array.isArray(edges) ? edges : [];
852
796
  const reachable = reachableFrom(list, linkList);
853
- const downstreamLeads = list.filter((n) => n.kind === 'lead' && n.id !== 'lead' && reachable.has(n.id));
797
+ const soloLeads = soloLeadNodeIds(list, linkList);
798
+ const downstreamLeads = list.filter((n) => n.kind === 'lead' && n.id !== 'lead' && reachable.has(n.id) && !soloLeads.has(n.id));
854
799
  if (!downstreamLeads.length) return new Set();
855
800
  const hasOut = new Set(linkList.map((e) => e.from));
856
801
  const parents = new Map();
@@ -1104,22 +1049,24 @@ window.__ModuleLoader__.load({
1104
1049
  const task = String(entry.task || '').trim();
1105
1050
  const rest = nodes.filter((n) => n.id !== 'lead');
1106
1051
  if (!rest.length) return { error: '画布上还没有可执行的节点' };
1107
- // Nodes the entry Lead cannot reach are skipped rather than refused; the
1108
- // canvas marks them so the user can see what will not run.
1052
+ // Unconnected nodes, solo Lead-to-Lead nodes, and dangling dead-end agents
1053
+ // are shown dashed on the canvas and skipped at run time.
1109
1054
  const reachableIds = reachableFrom(nodes, edges);
1055
+ const soloLeads = soloLeadNodeIds(nodes, edges);
1056
+ const deadEnds = deadEndNodeIds(nodes, edges);
1057
+ const isInactive = (n) => !reachableIds.has(n.id) || soloLeads.has(n.id) || deadEnds.has(n.id);
1110
1058
 
1111
- const ids = new Set(rest.map((n) => n.id));
1112
- const planEdges = edges
1113
- .filter((e) => (e.from === 'lead' || ids.has(e.from)) && ids.has(e.to))
1114
- .map((e) => ({ from: e.from, to: e.to, type: e.type || 'prompt' }));
1115
-
1116
- // Unconnected nodes are left out of the plan instead of blocking the run.
1117
- const skipped = rest.filter((n) => !reachableIds.has(n.id));
1118
- const active = rest.filter((n) => reachableIds.has(n.id));
1059
+ const skipped = rest.filter((n) => isInactive(n));
1060
+ const active = rest.filter((n) => !isInactive(n));
1119
1061
  if (!active.length) {
1120
- return { error: '没有从入口 Lead 连通的节点,无法执行' };
1062
+ return { error: '没有从入口 Lead 连通的有效节点,无法执行' };
1121
1063
  }
1122
1064
 
1065
+ const activeIds = new Set(active.map((n) => n.id));
1066
+ const planEdges = edges
1067
+ .filter((e) => (e.from === 'lead' || activeIds.has(e.from)) && activeIds.has(e.to))
1068
+ .map((e) => ({ from: e.from, to: e.to, type: e.type || 'prompt' }));
1069
+
1123
1070
  return {
1124
1071
  plan: {
1125
1072
  task,
@@ -1134,6 +1081,7 @@ window.__ModuleLoader__.load({
1134
1081
  reasoning: n.reasoning || '',
1135
1082
  preset: n.preset === 'minimal' ? 'minimal' : 'standard',
1136
1083
  keepSession: Boolean(n.keepSession),
1084
+ memoryChildId: n.memoryChildId || '',
1137
1085
  // A structured link is the only thing that decides this: no separate switch.
1138
1086
  structured: planEdges.some((e) => e.from === n.id && e.type === 'structured'),
1139
1087
  fallbackModel: n.fallbackModel || '',
@@ -1347,6 +1295,7 @@ window.__ModuleLoader__.load({
1347
1295
  viewRef.current = view;
1348
1296
  const [statusById, setStatusById] = useState({});
1349
1297
  const [runsById, setRunsById] = useState({});
1298
+ const [sessionRunning, setSessionRunning] = useState(false);
1350
1299
  const [presets, setPresets] = useState(loadPresets);
1351
1300
  const [presetOpen, setPresetOpen] = useState(null);
1352
1301
  const [presetName, setPresetName] = useState('');
@@ -1372,14 +1321,28 @@ window.__ModuleLoader__.load({
1372
1321
  saveDoc(sessionId, { nodes, edges, enabled }, stamp === null ? undefined : stamp);
1373
1322
  }, [sessionId, nodes, edges, enabled]);
1374
1323
 
1324
+ const planSig = (nextEnabled, curNodes, curEdges) => {
1325
+ const res = buildPlan(curNodes, curEdges);
1326
+ const payload = res.error
1327
+ ? { enabled: nextEnabled, error: res.error }
1328
+ : { enabled: nextEnabled, plan: res.plan };
1329
+ return JSON.stringify(payload);
1330
+ };
1331
+
1375
1332
  // Any structural edit after enabling leaves the Host copy stale,
1376
- // except when the update came directly from the Host itself.
1333
+ // except pure position drags (same plan signature) or updates from Host.
1377
1334
  useEffect(() => {
1378
1335
  if (skipDirtyOnce.current) {
1379
1336
  skipDirtyOnce.current = false;
1380
1337
  return;
1381
1338
  }
1382
- if (enabled) setDirty(true);
1339
+ if (!enabled) return;
1340
+ const sig = planSig(true, nodes, edges);
1341
+ if (lastSync.current && sig === lastSync.current) {
1342
+ setDirty(false);
1343
+ return;
1344
+ }
1345
+ setDirty(true);
1383
1346
  }, [nodes, edges]);
1384
1347
 
1385
1348
  // A disabled canvas shows no run status at all.
@@ -1429,19 +1392,16 @@ window.__ModuleLoader__.load({
1429
1392
  if (!face || typeof face.command !== 'function') { flash(t('syncFailed')); return; }
1430
1393
  const curNodes = Array.isArray(overrideNodes) ? overrideNodes : nodesRef.current;
1431
1394
  const curEdges = Array.isArray(overrideEdges) ? overrideEdges : edgesRef.current;
1432
- const res = buildPlan(curNodes, curEdges);
1433
- const payload = res.error
1434
- ? { enabled: nextEnabled, error: res.error }
1435
- : { enabled: nextEnabled, plan: res.plan };
1436
- const sig = JSON.stringify(payload);
1437
- if (sig === lastSync.current) { flash(t('upToDate')); return; }
1395
+ const sig = planSig(nextEnabled, curNodes, curEdges);
1396
+ if (sig === lastSync.current) { setDirty(false); flash(t('upToDate')); return; }
1438
1397
  const line = '/canvas-sync ' + encodeURIComponent(sig);
1398
+ const hasStandardAgent = nextEnabled && curNodes.some((n) => n && n.kind !== 'lead' && (n.preset || 'standard') !== 'minimal');
1439
1399
  face.command(line).then((ack) => {
1440
1400
  if (ack && ack.ok) {
1441
1401
  lastSync.current = sig;
1442
1402
  setDirty(false);
1443
1403
  snapshotStaleCatalog();
1444
- flash(t('syncedToHost'));
1404
+ flash(hasStandardAgent ? t('syncedWithStdWarn') : t('syncedToHost'));
1445
1405
  } else {
1446
1406
  flash(t('syncFailed'));
1447
1407
  }
@@ -1527,11 +1487,17 @@ window.__ModuleLoader__.load({
1527
1487
  const timing = timingProj && timingProj.values && timingProj.values.subagentTiming;
1528
1488
  if (entry.id) {
1529
1489
  const prev = nextRuns[nodeId];
1490
+ const prevHistory = prev && Array.isArray(prev.history) ? prev.history : [];
1491
+ const exists = prevHistory.some((hItem) => hItem.childId === entry.id);
1492
+ const history = exists
1493
+ ? prevHistory
1494
+ : prevHistory.concat([{ childId: entry.id, label, index: prevHistory.length + 1 }]);
1530
1495
  nextRuns[nodeId] = {
1531
1496
  childId: entry.id,
1532
1497
  label,
1533
1498
  mode: entry.mode || 'continuable',
1534
- count: prev ? prev.count + 1 : 1,
1499
+ count: history.length,
1500
+ history,
1535
1501
  };
1536
1502
  }
1537
1503
  if (child && child.running) {
@@ -1565,6 +1531,7 @@ window.__ModuleLoader__.load({
1565
1531
  const stop = () => { if (timer) { clearInterval(timer); timer = null; } };
1566
1532
  let wasRunning = false;
1567
1533
  try { wasRunning = Boolean(face.getSnapshot().running); } catch (_e) { wasRunning = false; }
1534
+ setSessionRunning(wasRunning);
1568
1535
  read();
1569
1536
  if (wasRunning) timer = setInterval(read, 700);
1570
1537
  const onSnapshot = () => {
@@ -1572,6 +1539,7 @@ window.__ModuleLoader__.load({
1572
1539
  try { running = Boolean(face.getSnapshot().running); } catch (_e) { running = false; }
1573
1540
  const finished = !running && wasRunning;
1574
1541
  wasRunning = running;
1542
+ setSessionRunning(running);
1575
1543
  if (running && !timer) { read(); timer = setInterval(read, 700); }
1576
1544
  if (!running && timer) { stop(); read(); }
1577
1545
  if (finished && typeof sessions.refreshProjections === 'function') {
@@ -2295,6 +2263,7 @@ window.__ModuleLoader__.load({
2295
2263
  const threshold = 12 / (viewRef.current.k || 1);
2296
2264
  const from = cutRef.current;
2297
2265
  const steps = Math.max(1, Math.ceil(Math.hypot(p.x - from.x, p.y - from.y) / 6));
2266
+ const nodeMap = new Map(nodes.map((n) => [n.id, n]));
2298
2267
  for (let step = 1; step <= steps; step += 1) {
2299
2268
  const t = step / steps;
2300
2269
  const canvasSpot = {
@@ -2303,8 +2272,8 @@ window.__ModuleLoader__.load({
2303
2272
  };
2304
2273
  for (const edge of edges) {
2305
2274
  if (cutHits.current.has(edge.id)) continue;
2306
- const source = nodes.find((n) => n.id === edge.from);
2307
- const target = nodes.find((n) => n.id === edge.to);
2275
+ const source = nodeMap.get(edge.from);
2276
+ const target = nodeMap.get(edge.to);
2308
2277
  if (!source || !target) continue;
2309
2278
  if (distanceToEdge(canvasSpot, source, target, edge.type) <= threshold) {
2310
2279
  cutHits.current.add(edge.id);
@@ -2668,13 +2637,66 @@ window.__ModuleLoader__.load({
2668
2637
  isOpen && h('div', { style: S.menu, onMouseDown: (e) => e.stopPropagation() }, rows),
2669
2638
  );
2670
2639
  };
2671
- const memoryToggle = (node) => h('button', {
2672
- style: node.keepSession ? S.toggleSwitchOn : S.toggleSwitch,
2673
- type: 'button',
2674
- title: t('tipMemory'),
2675
- onMouseDown: (e) => e.stopPropagation(),
2676
- onClick: () => updateNode(node.id, { keepSession: !node.keepSession }),
2677
- }, node.keepSession ? t('on') : t('off'));
2640
+ const memoryToggle = (node) => {
2641
+ const runInfo = runsById[node.id];
2642
+ const history = (runInfo && Array.isArray(runInfo.history)) ? runInfo.history : [];
2643
+ const showPicker = Boolean(node.keepSession);
2644
+ const key = 'm:' + node.id;
2645
+ const isOpen = openModelFor === key;
2646
+ const pickedItem = node.memoryChildId
2647
+ ? history.find((item) => item.childId === node.memoryChildId)
2648
+ : undefined;
2649
+ const pickLabel = !node.memoryChildId
2650
+ ? t('memLatest')
2651
+ : (pickedItem ? ('#' + pickedItem.index) : String(node.memoryChildId).slice(-6));
2652
+ const toggleBtn = h('button', {
2653
+ style: showPicker
2654
+ ? { ...(node.keepSession ? S.toggleSwitchOn : S.toggleSwitch), flex: '0 0 34px', width: '34px' }
2655
+ : (node.keepSession ? S.toggleSwitchOn : S.toggleSwitch),
2656
+ type: 'button',
2657
+ title: t('tipMemory'),
2658
+ onMouseDown: (e) => e.stopPropagation(),
2659
+ onClick: () => updateNode(node.id, { keepSession: !node.keepSession }),
2660
+ }, node.keepSession ? t('on') : t('off'));
2661
+ if (!showPicker) return toggleBtn;
2662
+ const rows = [
2663
+ h('div', {
2664
+ key: 'latest',
2665
+ style: !node.memoryChildId ? { ...S.menuRow, background: C.hover, color: C.accent } : S.menuRow,
2666
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
2667
+ onMouseLeave: (e) => { e.currentTarget.style.background = !node.memoryChildId ? C.hover : 'transparent'; },
2668
+ onClick: () => { updateNode(node.id, { memoryChildId: '' }); setOpenModelFor(null); },
2669
+ }, t('memLatestOpt')),
2670
+ ...history.map((item) => {
2671
+ const selectedRow = node.memoryChildId === item.childId;
2672
+ return h('div', {
2673
+ key: item.childId,
2674
+ style: selectedRow ? { ...S.menuRow, background: C.hover, color: C.accent } : S.menuRow,
2675
+ title: item.childId,
2676
+ onMouseEnter: (e) => { e.currentTarget.style.background = C.hover; },
2677
+ onMouseLeave: (e) => { e.currentTarget.style.background = selectedRow ? C.hover : 'transparent'; },
2678
+ onClick: () => { updateNode(node.id, { memoryChildId: item.childId }); setOpenModelFor(null); },
2679
+ }, t('memRunOpt').replace('{n}', String(item.index)) + ' (' + String(item.childId).slice(-5) + ')');
2680
+ }),
2681
+ !history.length && h('div', { key: 'mem-empty', style: S.presetEmpty }, t('memEmpty')),
2682
+ ];
2683
+ return h('div', { style: { display: 'flex', alignItems: 'center', gap: '4px', flex: '1 1 auto', minWidth: 0 } },
2684
+ toggleBtn,
2685
+ h('div', { ref: isOpen ? dropdownRef : undefined, style: { position: 'relative', flex: '1 1 auto', minWidth: 0 } },
2686
+ h('button', {
2687
+ style: S.selectBtn,
2688
+ type: 'button',
2689
+ title: t('tipMemoryPick'),
2690
+ onMouseDown: (e) => e.stopPropagation(),
2691
+ onClick: () => setOpenModelFor(isOpen ? null : key),
2692
+ },
2693
+ h('span', { style: S.selectText }, pickLabel),
2694
+ h('span', { style: S.caret }, '▾'),
2695
+ ),
2696
+ isOpen && h('div', { style: S.menu, onMouseDown: (e) => e.stopPropagation() }, rows),
2697
+ ),
2698
+ );
2699
+ };
2678
2700
 
2679
2701
  const reasoningControl = (node) => {
2680
2702
  const key = 'r:' + node.id;
@@ -2766,11 +2788,14 @@ window.__ModuleLoader__.load({
2766
2788
  }
2767
2789
  const reachableIds = reachableFrom(nodes, edges);
2768
2790
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
2791
+ const soloLeadIds = soloLeadNodeIds(nodes, edges);
2769
2792
  const deadEndIds = deadEndNodeIds(nodes, edges);
2770
2793
 
2771
- // Identify intermediate/final Lead nodes whose upstream subagents are all
2772
- // finished and whose downstream has not started yet ("Ready for Lead").
2794
+ // Identify intermediate Lead nodes waiting for a decision ("Ready for Lead")
2795
+ // and terminal Lead nodes: a terminal Lead glows only while the conversation
2796
+ // is still streaming its final review; once the turn finishes it settles to Done.
2773
2797
  const leadReadyIds = new Set();
2798
+ const leadDoneIds = new Set();
2774
2799
  if (enabled) {
2775
2800
  for (const n of nodes) {
2776
2801
  if (n.kind !== 'lead' || n.id === 'lead' || !reachableIds.has(n.id)) continue;
@@ -2780,10 +2805,17 @@ window.__ModuleLoader__.load({
2780
2805
  if (!upIds.length) continue;
2781
2806
  const upAgents = upIds.filter((id) => nodeById.get(id).kind !== 'lead');
2782
2807
  if (!upAgents.length) continue;
2783
- const allUpDone = upAgents.every((id) => statusById[id] === 'done');
2808
+ const allUpDone = upAgents.every((id) => statusById[id] === 'done' || statusById[id] === 'failed');
2809
+ if (!allUpDone) continue;
2784
2810
  const downIds = edges.filter((e) => e.from === n.id).map((e) => e.to);
2785
- const anyDownStarted = downIds.some((id) => Boolean(statusById[id]));
2786
- if (allUpDone && !anyDownStarted) leadReadyIds.add(n.id);
2811
+ if (!downIds.length) {
2812
+ if (sessionRunning) leadReadyIds.add(n.id);
2813
+ else leadDoneIds.add(n.id);
2814
+ } else {
2815
+ const anyDownStarted = downIds.some((id) => Boolean(statusById[id]));
2816
+ if (!anyDownStarted) leadReadyIds.add(n.id);
2817
+ else leadDoneIds.add(n.id);
2818
+ }
2787
2819
  }
2788
2820
  }
2789
2821
 
@@ -2799,18 +2831,27 @@ window.__ModuleLoader__.load({
2799
2831
  const toRunning = enabled && statusById[edge.to] === 'running';
2800
2832
  const fromReady = edge.from === 'lead'
2801
2833
  || from.kind === 'lead'
2802
- || statusById[edge.from] === 'done';
2834
+ || statusById[edge.from] === 'done'
2835
+ || statusById[edge.from] === 'failed';
2803
2836
  const isFlowing = enabled && !highlighted && (
2804
2837
  (toRunning && fromReady)
2805
- || (leadReadyIds.has(edge.to) && statusById[edge.from] === 'done')
2838
+ || (leadReadyIds.has(edge.to) && (statusById[edge.from] === 'done' || statusById[edge.from] === 'failed'))
2806
2839
  );
2807
- const isCompletedLink = enabled && !highlighted && statusById[edge.from] === 'done'
2808
- && (statusById[edge.to] === 'done' || statusById[edge.to] === 'running' || leadReadyIds.has(edge.to));
2840
+ const fromSettled = edge.from === 'lead'
2841
+ || statusById[edge.from] === 'done'
2842
+ || statusById[edge.from] === 'failed'
2843
+ || leadDoneIds.has(edge.from);
2844
+ const toSettled = statusById[edge.to] === 'done'
2845
+ || statusById[edge.to] === 'running'
2846
+ || statusById[edge.to] === 'failed'
2847
+ || leadReadyIds.has(edge.to)
2848
+ || leadDoneIds.has(edge.to);
2849
+ const isCompletedLink = enabled && !highlighted && fromSettled && toSettled;
2809
2850
  const dimmed = hasSel && !linkedToSel && !highlighted && !isFlowing;
2810
2851
  const strokeColor = highlighted ? '#e5534b' : color;
2811
2852
  const baseWidth = highlighted ? 3 : (linkedToSel || isFlowing ? 2.6 : 2);
2812
2853
  const baseOpacity = dimmed ? 0.26 : (isFlowing || linkedToSel ? 1 : (isCompletedLink ? 0.92 : 0.78));
2813
- const useGlow = fxLevel === 'vivid' && !dimmed && (highlighted || isFlowing || linkedToSel || edge.type !== 'prompt');
2854
+ const useGlow = fxLevel === 'vivid' && !dimmed;
2814
2855
  const showDashFlow = isFlowing && fxLevel !== 'minimal';
2815
2856
  const showBead = isFlowing && fxLevel === 'vivid';
2816
2857
 
@@ -3198,12 +3239,15 @@ window.__ModuleLoader__.load({
3198
3239
  }),
3199
3240
  );
3200
3241
  const isOrphan = node.id !== 'lead' && !reachableIds.has(node.id);
3242
+ const isSoloLead = soloLeadIds.has(node.id);
3201
3243
  const isDeadEnd = deadEndIds.has(node.id);
3244
+ const isInactive = isOrphan || isSoloLead || isDeadEnd;
3202
3245
  const isSelected = selectedSet.has(node.id);
3203
3246
  const nodeStatus = enabled ? statusById[node.id] : undefined;
3204
3247
  const isLeadReady = leadReadyIds.has(node.id);
3248
+ const isLeadDone = leadDoneIds.has(node.id);
3205
3249
  const isRunning = !isLeadKind && nodeStatus === 'running';
3206
- const isDone = !isLeadKind && nodeStatus === 'done';
3250
+ const isDone = (!isLeadKind && nodeStatus === 'done') || isLeadDone;
3207
3251
  const isFailed = !isLeadKind && nodeStatus === 'failed';
3208
3252
  const isPulsing = (isRunning || isLeadReady) && fxLevel !== 'minimal';
3209
3253
  const nodeClass = 'dsh-wc-node'
@@ -3233,10 +3277,10 @@ window.__ModuleLoader__.load({
3233
3277
  left: node.x + WORLD_PAD,
3234
3278
  top: node.y + WORLD_PAD,
3235
3279
  ...(isLeadKind ? S.leadNode : null),
3236
- ...(isOrphan ? S.orphanNode : null),
3280
+ ...(isInactive ? S.orphanNode : null),
3237
3281
  ...(stateStyle || null),
3238
3282
  },
3239
- title: isOrphan ? t('orphanTip') : undefined,
3283
+ title: isOrphan ? t('orphanTip') : (isSoloLead ? t('tipSoloLead') : (isDeadEnd ? t('tipDeadEnd') : undefined)),
3240
3284
  onMouseDown: (e) => onNodeDown(e, node.id),
3241
3285
  },
3242
3286
  h('div', {
@@ -3256,30 +3300,33 @@ window.__ModuleLoader__.load({
3256
3300
  (() => {
3257
3301
  const latestRun = !isLeadKind ? runsById[node.id] : null;
3258
3302
  const statusColor = isLeadReady ? '#2f81f7'
3259
- : isLeadKind ? C.dim
3260
- : nodeStatus === 'running' ? '#2f81f7'
3261
- : nodeStatus === 'failed' ? '#e5534b'
3262
- : nodeStatus === 'done' ? '#3fb950' : C.dim;
3303
+ : isLeadDone ? '#3fb950'
3304
+ : isLeadKind ? C.dim
3305
+ : nodeStatus === 'running' ? '#2f81f7'
3306
+ : nodeStatus === 'failed' ? '#e5534b'
3307
+ : nodeStatus === 'done' ? '#3fb950' : C.dim;
3263
3308
  const statusTint = isLeadReady || nodeStatus === 'running'
3264
3309
  ? 'rgba(47,129,247,0.14)'
3265
3310
  : nodeStatus === 'failed'
3266
3311
  ? 'rgba(229,83,75,0.14)'
3267
- : nodeStatus === 'done'
3312
+ : isDone
3268
3313
  ? 'rgba(63,185,80,0.14)'
3269
3314
  : 'transparent';
3270
3315
  const statusLabel = isOrphan ? t('stOrphan')
3271
- : isLeadReady ? t('stLeadReady')
3272
- : isLeadKind ? t('stLead')
3273
- : nodeStatus === 'running' ? t('stRunning')
3274
- : nodeStatus === 'failed' ? t('stFailed')
3275
- : nodeStatus === 'done' ? t('stDone') : t('stPending');
3316
+ : isSoloLead ? t('stSoloLead')
3317
+ : isLeadReady ? t('stLeadReady')
3318
+ : isLeadDone ? t('stDone')
3319
+ : isLeadKind ? t('stLead')
3320
+ : nodeStatus === 'running' ? t('stRunning')
3321
+ : nodeStatus === 'failed' ? t('stFailed')
3322
+ : nodeStatus === 'done' ? t('stDone') : t('stPending');
3276
3323
  const glyph = nodeStatus === 'running'
3277
3324
  ? h('span', {
3278
3325
  className: fxLevel !== 'minimal' ? 'dsh-wc-dot-live' : undefined,
3279
3326
  style: { width: '6px', height: '6px', borderRadius: '50%', background: statusColor, flex: '0 0 auto' },
3280
3327
  })
3281
3328
  : isLeadReady ? h('span', { className: fxLevel !== 'minimal' ? 'dsh-wc-dot-live' : undefined }, '⏸')
3282
- : nodeStatus === 'done' ? '✓'
3329
+ : isDone ? '✓'
3283
3330
  : nodeStatus === 'failed' ? '✕' : null;
3284
3331
  if (latestRun) {
3285
3332
  const label = enabled ? statusLabel : t('openChat');
@@ -3430,7 +3477,7 @@ window.__ModuleLoader__.load({
3430
3477
  try { console.error('[workflow-canvas] apply failed', error); } catch (_e) { /* ignore */ }
3431
3478
  }
3432
3479
  },
3433
- __test: { topoOrder, wouldCycle, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, zoomAroundPoint, scrubZoom, buildWorkflowScript, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
3480
+ __test: { topoOrder, wouldCycle, soloLeadNodeIds, layoutGraph, builtinTemplates, deadEndNodeIds, nextEffectLevel, zoomAroundPoint, scrubZoom, buildPlan, loadDoc, saveDoc, storageKey, socketCenterY, distanceToEdge, edgeCurve },
3434
3481
  };
3435
3482
  },
3436
3483
  });