dsh-workflow-canvas 0.2.4 → 1.0.1
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/README.md +77 -111
- package/README.zh.md +78 -75
- package/client.js +286 -171
- package/docs/DETAIL.md +13 -10
- package/docs/images/add-node-shift-a.gif +0 -0
- package/docs/images/connect-and-cut.gif +0 -0
- package/docs/images/lead-pause-resume.gif +0 -0
- package/docs/images/node-config.gif +0 -0
- package/docs/images/node-entry-en.png +0 -0
- package/docs/images/node-entry-zh.png +0 -0
- package/docs/images/node-lead-en.png +0 -0
- package/docs/images/node-lead-zh.png +0 -0
- package/docs/images/node-subagent-en.png +0 -0
- package/docs/images/node-subagent-zh.png +0 -0
- package/docs/images/parallel-and-inspect.gif +0 -0
- package/index.js +162 -56
- package/package.json +1 -1
- package/skills/workflow-canvas/SKILL.md +3 -1
package/docs/DETAIL.md
CHANGED
|
@@ -9,14 +9,16 @@ are performed by the conversation itself.
|
|
|
9
9
|
|
|
10
10
|
- **Subagent node** (green top bar): spawns a child agent with its own
|
|
11
11
|
`provider` / `model` / `reasoning effort` / capability scope (`standard` or
|
|
12
|
-
`minimal
|
|
13
|
-
**Fallback** retries once on another model.
|
|
12
|
+
`minimal`, bounded by the main chat permission mode). Optional **Memory** reuses
|
|
13
|
+
the node's child session; optional **Fallback** retries once on another model.
|
|
14
14
|
- **Lead node** (blue top bar): performed by the conversation, never spawned. The
|
|
15
|
-
entry node carries the overall task;
|
|
15
|
+
entry node carries the overall task; intermediate Lead nodes pause for your
|
|
16
|
+
decision, and a terminal Lead finishes in one shot without an extra callback.
|
|
16
17
|
- **Sockets are typed** (`prompt` / `structured` / `session`); a link only joins
|
|
17
18
|
the same type (either direction), and cycles are blocked immediately. Drag a
|
|
18
19
|
connected input away to detach.
|
|
19
|
-
-
|
|
20
|
+
- Inactive nodes (unreachable from entry, solo chained Leads with no subagent
|
|
21
|
+
upstream, or dangling dead-end subagents) are drawn dashed and skipped at run time.
|
|
20
22
|
- Wheel zooms around the cursor; middle-drag (or `Space` + drag) pans; `⊡ Fit`
|
|
21
23
|
fits all nodes into the visible viewport; the percentage button resets to 100%
|
|
22
24
|
on the Lead.
|
|
@@ -45,12 +47,13 @@ node positions survive.
|
|
|
45
47
|
|
|
46
48
|
## Running
|
|
47
49
|
|
|
48
|
-
Subagent nodes run in
|
|
49
|
-
supports `task` (override the entry task for template
|
|
50
|
-
(discard a paused run)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
Subagent nodes run in an event-driven concurrency pool (up to 4) via
|
|
51
|
+
`canvas_workflow`, which supports `task` (override the entry task for template
|
|
52
|
+
reuse), `reset: true` (discard a paused run), and `clearMemory: true` (forget
|
|
53
|
+
saved `keepSession` memories). While enabled, a per-session runtime context
|
|
54
|
+
notifies the agent automatically. Intermediate Lead nodes pause with
|
|
55
|
+
`status: "need-lead"` and report `failed` / `emptyOutputs` plus `session`
|
|
56
|
+
handovers; a terminal Lead completes directly with `status: "done"` and `finalLead`.
|
|
54
57
|
|
|
55
58
|
## Memory
|
|
56
59
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -24,9 +24,14 @@ import { fileURLToPath } from 'node:url';
|
|
|
24
24
|
const canvasBySession = new Map();
|
|
25
25
|
/** In-flight run progress per Session id. */
|
|
26
26
|
const runBySession = new Map();
|
|
27
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Two separate maps by design:
|
|
29
|
+
* - `childByNode`: persisted memory slot written ONLY when `keepSession` is ON,
|
|
30
|
+
* so temporary `keepSession=false` runs never overwrite saved memory.
|
|
31
|
+
* - `liveChild`: latest child id in this process (updated even when Memory is OFF)
|
|
32
|
+
* so downstream `session-ref` purple links can always continue the upstream run.
|
|
33
|
+
*/
|
|
28
34
|
const childByNode = new Map();
|
|
29
|
-
/** node id → child id created in this process, safe to resume. */
|
|
30
35
|
const liveChild = new Map();
|
|
31
36
|
|
|
32
37
|
function storePath() {
|
|
@@ -222,8 +227,10 @@ async function spawnOnce(scope, plan, node, results, parent, signal, route, forc
|
|
|
222
227
|
}
|
|
223
228
|
try {
|
|
224
229
|
if (activation && activation.childId) {
|
|
225
|
-
childByNode.set(childKey(node.id), activation.childId);
|
|
226
230
|
liveChild.set(childKey(node.id), activation.childId);
|
|
231
|
+
// Only overwrite the persisted memory slot when Memory is ON, so a
|
|
232
|
+
// temporary keepSession=false experiment never destroys saved memory.
|
|
233
|
+
if (node.keepSession) childByNode.set(childKey(node.id), activation.childId);
|
|
227
234
|
}
|
|
228
235
|
let result;
|
|
229
236
|
try {
|
|
@@ -257,19 +264,20 @@ async function spawnOnce(scope, plan, node, results, parent, signal, route, forc
|
|
|
257
264
|
/* activation refused (e.g. cold session gone): fall through to a fresh session */
|
|
258
265
|
}
|
|
259
266
|
|
|
260
|
-
// Memory: prefer
|
|
261
|
-
//
|
|
262
|
-
//
|
|
267
|
+
// Memory: prefer an explicitly pinned `memoryChildId` from the node dropdown,
|
|
268
|
+
// then the saved memory slot (`childByNode`), then this process's live child.
|
|
269
|
+
// A cold resume that the Host refuses falls through to a fresh session.
|
|
263
270
|
if (node.keepSession) {
|
|
271
|
+
const pinned = typeof node.memoryChildId === 'string' ? node.memoryChildId.trim() : '';
|
|
272
|
+
const saved = childByNode.get(childKey(node.id));
|
|
264
273
|
const inProcess = liveChild.get(childKey(node.id));
|
|
265
|
-
const
|
|
266
|
-
const previous = inProcess || fromDisk;
|
|
274
|
+
const previous = pinned || saved || inProcess;
|
|
267
275
|
if (previous) {
|
|
268
276
|
const resumed = await run(previous);
|
|
269
277
|
if (resumed.ok) return resumed;
|
|
270
278
|
if (resumed.reason === 'activation-failed') {
|
|
271
|
-
liveChild.delete(childKey(node.id));
|
|
272
|
-
childByNode.delete(childKey(node.id));
|
|
279
|
+
if (previous === inProcess) liveChild.delete(childKey(node.id));
|
|
280
|
+
if (previous === saved) childByNode.delete(childKey(node.id));
|
|
273
281
|
} else {
|
|
274
282
|
return resumed;
|
|
275
283
|
}
|
|
@@ -310,40 +318,51 @@ async function spawnNode(scope, plan, node, results, parent, signal, sid, failed
|
|
|
310
318
|
return { ok: false, empty: false, reason, text: retry.text + '\n(重试仍失败:' + reason + ')' };
|
|
311
319
|
}
|
|
312
320
|
|
|
313
|
-
/** Ids reachable from the entry Lead; every other node is skipped at run time. */
|
|
321
|
+
/** Ids reachable from the entry Lead via O(V + E) BFS; every other node is skipped at run time. */
|
|
314
322
|
function reachableFrom(plan) {
|
|
323
|
+
const adj = new Map();
|
|
324
|
+
for (const e of (plan && plan.edges) || []) {
|
|
325
|
+
if (!e || !e.from || !e.to) continue;
|
|
326
|
+
if (!adj.has(e.from)) adj.set(e.from, []);
|
|
327
|
+
adj.get(e.from).push(e.to);
|
|
328
|
+
}
|
|
315
329
|
const set = new Set(['lead']);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
for (const
|
|
320
|
-
if (
|
|
330
|
+
const queue = ['lead'];
|
|
331
|
+
for (let i = 0; i < queue.length; i += 1) {
|
|
332
|
+
const cur = queue[i];
|
|
333
|
+
for (const next of adj.get(cur) || []) {
|
|
334
|
+
if (!set.has(next)) { set.add(next); queue.push(next); }
|
|
321
335
|
}
|
|
322
336
|
}
|
|
323
337
|
return set;
|
|
324
338
|
}
|
|
325
339
|
|
|
326
340
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
341
|
+
* Classify inactive nodes that are rendered dashed on the canvas and skipped at run time:
|
|
342
|
+
* - unreachable orphans
|
|
343
|
+
* - solo chained Leads (zero reachable subagent upstream)
|
|
344
|
+
* - dangling dead-end subagents (zero outgoing edges while an active non-ancestor downstream Lead exists)
|
|
331
345
|
*/
|
|
332
|
-
function
|
|
346
|
+
function inactiveNodeSets(nodes, edges) {
|
|
333
347
|
const list = withoutEntry(nodes);
|
|
334
348
|
const linkList = Array.isArray(edges) ? edges : [];
|
|
335
|
-
const warnings = [];
|
|
336
|
-
if (!list.length) return warnings;
|
|
337
|
-
|
|
338
349
|
const reachable = reachableFrom({ edges: linkList });
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
350
|
+
const byId = new Map(list.map((n) => [n.id, n]));
|
|
351
|
+
|
|
352
|
+
const soloLeads = new Set();
|
|
353
|
+
for (const n of list) {
|
|
354
|
+
if (n.kind !== 'lead' || !reachable.has(n.id)) continue;
|
|
355
|
+
const hasAgentUp = linkList.some((e) => {
|
|
356
|
+
if (!e || e.to !== n.id || !reachable.has(e.from) || e.from === 'lead') return false;
|
|
357
|
+
const src = byId.get(e.from);
|
|
358
|
+
return Boolean(src && src.kind !== 'lead');
|
|
359
|
+
});
|
|
360
|
+
if (!hasAgentUp) soloLeads.add(n.id);
|
|
343
361
|
}
|
|
344
362
|
|
|
345
|
-
const
|
|
346
|
-
|
|
363
|
+
const deadEnds = new Set();
|
|
364
|
+
const activeLeads = list.filter((n) => n.kind === 'lead' && reachable.has(n.id) && !soloLeads.has(n.id));
|
|
365
|
+
if (activeLeads.length) {
|
|
347
366
|
const hasOut = new Set(linkList.map((e) => e.from));
|
|
348
367
|
const parents = new Map();
|
|
349
368
|
for (const e of linkList) {
|
|
@@ -361,16 +380,44 @@ function analyzeCanvasWarnings(nodes, edges) {
|
|
|
361
380
|
}
|
|
362
381
|
return seen;
|
|
363
382
|
};
|
|
364
|
-
const
|
|
365
|
-
if (n.kind === 'lead' || !reachable.has(n.id) || hasOut.has(n.id))
|
|
383
|
+
for (const n of list) {
|
|
384
|
+
if (n.kind === 'lead' || !reachable.has(n.id) || hasOut.has(n.id)) continue;
|
|
366
385
|
const anc = ancestorsOf(n.id);
|
|
367
|
-
|
|
368
|
-
});
|
|
369
|
-
if (deadEnds.length) {
|
|
370
|
-
warnings.push('以下子代理节点没有出边,产出未显式连入下游或终审 Lead:'
|
|
371
|
-
+ deadEnds.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
386
|
+
if (activeLeads.some((ln) => !anc.has(ln.id))) deadEnds.add(n.id);
|
|
372
387
|
}
|
|
373
388
|
}
|
|
389
|
+
return { reachable, soloLeads, deadEnds };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Detect structural warnings on a canvas plan (all three classes are rendered
|
|
394
|
+
* dashed on the canvas and skipped at run time):
|
|
395
|
+
* 1. Unreachable nodes.
|
|
396
|
+
* 2. Solo chained Lead nodes with zero subagent upstream.
|
|
397
|
+
* 3. Dangling dead-end subagent nodes with zero outgoing edges.
|
|
398
|
+
*/
|
|
399
|
+
function analyzeCanvasWarnings(nodes, edges) {
|
|
400
|
+
const list = withoutEntry(nodes);
|
|
401
|
+
const linkList = Array.isArray(edges) ? edges : [];
|
|
402
|
+
const warnings = [];
|
|
403
|
+
if (!list.length) return warnings;
|
|
404
|
+
|
|
405
|
+
const { reachable, soloLeads, deadEnds } = inactiveNodeSets(list, linkList);
|
|
406
|
+
const orphans = list.filter((n) => !reachable.has(n.id));
|
|
407
|
+
if (orphans.length) {
|
|
408
|
+
warnings.push('以下节点未从入口 Lead 连通,运行时会被跳过:'
|
|
409
|
+
+ orphans.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
410
|
+
}
|
|
411
|
+
const soloList = list.filter((n) => soloLeads.has(n.id));
|
|
412
|
+
if (soloList.length) {
|
|
413
|
+
warnings.push('以下 Lead 节点仅串联了其他 Lead、未连入子代理,运行时不生效:'
|
|
414
|
+
+ soloList.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
415
|
+
}
|
|
416
|
+
const deadList = list.filter((n) => deadEnds.has(n.id));
|
|
417
|
+
if (deadList.length) {
|
|
418
|
+
warnings.push('以下子代理节点没有出边,产出未连入下游或终审 Lead,运行时不生效:'
|
|
419
|
+
+ deadList.map((n) => (n.label || n.id) + '(' + n.id + ')').join('、'));
|
|
420
|
+
}
|
|
374
421
|
return warnings;
|
|
375
422
|
}
|
|
376
423
|
|
|
@@ -521,7 +568,7 @@ function normalizeCanvas(args) {
|
|
|
521
568
|
function applyPatch(plan, args) {
|
|
522
569
|
const nodes = withoutEntry(plan.nodes).map((n) => ({ ...n }));
|
|
523
570
|
const byId = new Map(nodes.map((n) => [n.id, n]));
|
|
524
|
-
const ALLOWED = ['label', 'role', 'provider', 'model', 'reasoning', 'preset', 'keepSession', 'structured', 'fallbackModel', 'fallbackProvider'];
|
|
571
|
+
const ALLOWED = ['label', 'role', 'provider', 'model', 'reasoning', 'preset', 'keepSession', 'memoryChildId', 'structured', 'fallbackModel', 'fallbackProvider'];
|
|
525
572
|
const touched = [];
|
|
526
573
|
for (const patch of args && Array.isArray(args.nodes) ? args.nodes : []) {
|
|
527
574
|
// 'lead' is the reserved entry node and is never edited here.
|
|
@@ -674,8 +721,9 @@ function sessionIdFromContext(assembleCtx) {
|
|
|
674
721
|
|
|
675
722
|
/**
|
|
676
723
|
* Per-turn runtime prompt context injected ONLY for the session whose canvas is
|
|
677
|
-
* currently enabled.
|
|
678
|
-
*
|
|
724
|
+
* currently enabled. DSH invokes `systemPrompt.context` for both main chats AND
|
|
725
|
+
* spawned subagents, so strict `sid` matching (returning '' on miss) is required
|
|
726
|
+
* to prevent leaking canvas instructions into subagents and causing recursion.
|
|
679
727
|
*/
|
|
680
728
|
function buildActiveCanvasContext(sid) {
|
|
681
729
|
if (!sid) return '';
|
|
@@ -702,7 +750,9 @@ function buildActiveCanvasContext(sid) {
|
|
|
702
750
|
.map((n) => (n.kind === 'lead' ? '〔Lead〕' : '') + (n.label || n.id))
|
|
703
751
|
.join(' → ') + (nodes.length > 8 ? ' …' : '');
|
|
704
752
|
const hasTask = Boolean(String((plan && plan.task) || '').trim());
|
|
705
|
-
|
|
753
|
+
const prefix = String(sid) + '::';
|
|
754
|
+
const hasMemory = nodes.some((n) => n.keepSession && (liveChild.has(prefix + n.id) || childByNode.has(prefix + n.id)));
|
|
755
|
+
const lines = [
|
|
706
756
|
'[Workflow Canvas Active]',
|
|
707
757
|
'当前会话的右侧工作流画布处于「● 已启用」状态(共 ' + nodes.length + ' 个执行节点:' + preview + ';入口总任务:' + (hasTask ? '已填写' : '未填写') + ')。',
|
|
708
758
|
'- 若用户发出任务请求、布置工作或说「开始 / 执行 / 跑一次」:请直接调用 `canvas_workflow` 按画布编排执行('
|
|
@@ -710,7 +760,25 @@ function buildActiveCanvasContext(sid) {
|
|
|
710
760
|
+ '),不要绕过画布直接自己完成。',
|
|
711
761
|
'- 若用户在讨论或要求修改画布结构、模型、分工或连线:请先 `canvas_inspect` 再用 `canvas_patch` 就地修改,不要直接运行。',
|
|
712
762
|
'- 仅当用户明确只是闲聊、问无关问题或要求先停用画布时,才无需调用 `canvas_workflow`。',
|
|
713
|
-
]
|
|
763
|
+
];
|
|
764
|
+
if (hasMemory) {
|
|
765
|
+
lines.push('- 本会话已有开启「记忆」节点的历史子代理会话:若用户说「再跑一次 / 换个任务重跑」,请先简短询问用户是保留上次记忆继续(reset: true)还是清空记忆全新开跑(reset: true, clearMemory: true)。');
|
|
766
|
+
}
|
|
767
|
+
const stdCount = nodes.filter((n) => n.kind !== 'lead' && n.preset !== 'minimal').length;
|
|
768
|
+
if (stdCount >= 2) {
|
|
769
|
+
lines.push('- 本画布包含 ' + stdCount + ' 个可写/命令型(standard)子代理,受主对话权限上限约束;若任务涉及改代码、写文件或跑终端命令且当前主对话权限偏严格,请先简短提醒用户放开主对话权限再调 `canvas_workflow`,避免中途报错白耗额度。');
|
|
770
|
+
}
|
|
771
|
+
return lines.join('\n');
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
/** Detect permission / sandbox denial outcomes so we can circuit-break before burning downstream tokens. */
|
|
775
|
+
const PERMISSION_ERR_RE = /permission denied|access is denied|sandbox-local|windows-acl|win32error|eacces|eperm|approval required|not permitted|拒绝访问|权限不足|无权执行|沙箱拒绝/i;
|
|
776
|
+
function isPermissionFailure(outcome) {
|
|
777
|
+
if (!outcome) return false;
|
|
778
|
+
const text = String(outcome.text || '');
|
|
779
|
+
if (!outcome.ok && PERMISSION_ERR_RE.test(text)) return true;
|
|
780
|
+
if (text.includes('【未完全交付】') && PERMISSION_ERR_RE.test(text)) return true;
|
|
781
|
+
return false;
|
|
714
782
|
}
|
|
715
783
|
|
|
716
784
|
/** Takes a plan directly so tests can feed any plan shape (sync, generate, patch). */
|
|
@@ -735,19 +803,24 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
735
803
|
const order = orderNodes(plan);
|
|
736
804
|
if (!order) return { error: '存在环,无法执行有向无环图。' };
|
|
737
805
|
|
|
738
|
-
// Defense in depth: unreachable
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
806
|
+
// Defense in depth: unreachable orphans, solo chained Leads, and dangling
|
|
807
|
+
// dead-end subagents are skipped instead of wasting tokens or stalling.
|
|
808
|
+
const { reachable, soloLeads, deadEnds } = inactiveNodeSets(plan.nodes, plan.edges);
|
|
809
|
+
const isInactive = (n) => !reachable.has(n.id) || soloLeads.has(n.id) || deadEnds.has(n.id);
|
|
810
|
+
const runnable = order.filter((n) => !isInactive(n));
|
|
811
|
+
const skipped = order.filter((n) => isInactive(n)).map((n) => n.label || n.id);
|
|
812
|
+
if (!runnable.length) return { error: '没有从入口 Lead 连通的有效节点,无法执行。' };
|
|
813
|
+
|
|
814
|
+
if (opts.clearMemory === true && sid) {
|
|
815
|
+
const prefix = String(sid) + '::';
|
|
816
|
+
for (const key of Array.from(childByNode.keys())) {
|
|
817
|
+
if (key.startsWith(prefix)) childByNode.delete(key);
|
|
818
|
+
}
|
|
819
|
+
for (const key of Array.from(liveChild.keys())) {
|
|
820
|
+
if (key.startsWith(prefix)) liveChild.delete(key);
|
|
745
821
|
}
|
|
822
|
+
saveStore();
|
|
746
823
|
}
|
|
747
|
-
const runnable = order.filter((n) => reachable.has(n.id));
|
|
748
|
-
const skipped = order.filter((n) => !reachable.has(n.id)).map((n) => n.label || n.id);
|
|
749
|
-
if (!runnable.length) return { error: '没有从入口 Lead 连通的节点,无法执行。' };
|
|
750
|
-
|
|
751
824
|
if (opts.reset === true && sid) {
|
|
752
825
|
runBySession.delete(sid);
|
|
753
826
|
}
|
|
@@ -768,21 +841,27 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
768
841
|
.filter((id) => byId.has(id));
|
|
769
842
|
|
|
770
843
|
let leadResult = typeof opts.leadResult === 'string' ? opts.leadResult : undefined;
|
|
771
|
-
const
|
|
844
|
+
const rawMaxParallel = opts.maxParallel !== undefined ? opts.maxParallel : plan.maxParallel;
|
|
845
|
+
const MAX_PARALLEL = Number.isFinite(Number(rawMaxParallel))
|
|
846
|
+
? Math.max(1, Math.min(8, Math.floor(Number(rawMaxParallel))))
|
|
847
|
+
: 4;
|
|
772
848
|
// Event-driven concurrency pool: as soon as any node finishes, newly unblocked
|
|
773
849
|
// downstream agents start immediately instead of waiting for slower siblings.
|
|
774
850
|
const inFlight = new Map();
|
|
775
851
|
|
|
776
852
|
const isAborted = () => Boolean(exec && exec.signal && exec.signal.aborted);
|
|
853
|
+
const permBlocked = [];
|
|
854
|
+
let activationFailCount = 0;
|
|
855
|
+
let haltedReason = '';
|
|
777
856
|
|
|
778
857
|
const launchReadyAgents = () => {
|
|
779
|
-
if (isAborted() || inFlight.size >= MAX_PARALLEL) return;
|
|
858
|
+
if (isAborted() || haltedReason || inFlight.size >= MAX_PARALLEL) return;
|
|
780
859
|
const candidates = runnable.filter((n) => n.kind !== 'lead'
|
|
781
860
|
&& !state.done.has(n.id)
|
|
782
861
|
&& !inFlight.has(n.id)
|
|
783
862
|
&& depsOf(n).every((id) => state.done.has(id)));
|
|
784
863
|
for (const node of candidates) {
|
|
785
|
-
if (isAborted() || inFlight.size >= MAX_PARALLEL) break;
|
|
864
|
+
if (isAborted() || haltedReason || inFlight.size >= MAX_PARALLEL) break;
|
|
786
865
|
const promise = spawnNode(scope, plan, node, state.results, agent, exec.signal, sid, state.failed)
|
|
787
866
|
.then(
|
|
788
867
|
(outcome) => ({ node, outcome }),
|
|
@@ -797,6 +876,22 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
797
876
|
if (sid) runBySession.delete(sid);
|
|
798
877
|
return { error: '工作流执行已取消。' };
|
|
799
878
|
}
|
|
879
|
+
// On circuit-break halt, stop launching new downstream waves immediately,
|
|
880
|
+
// but let already in-flight siblings settle so no orphan promises or partial
|
|
881
|
+
// results are dropped before returning the halted report.
|
|
882
|
+
if (haltedReason && inFlight.size === 0) {
|
|
883
|
+
if (sid) runBySession.delete(sid);
|
|
884
|
+
saveStore();
|
|
885
|
+
return {
|
|
886
|
+
status: 'halted',
|
|
887
|
+
error: haltedReason,
|
|
888
|
+
results: state.results,
|
|
889
|
+
labels: state.labels,
|
|
890
|
+
failed: Object.values(state.failed),
|
|
891
|
+
emptyOutputs: Object.values(state.emptyOutputs),
|
|
892
|
+
skipped,
|
|
893
|
+
};
|
|
894
|
+
}
|
|
800
895
|
const remaining = runnable.filter((n) => !state.done.has(n.id));
|
|
801
896
|
if (!remaining.length) {
|
|
802
897
|
runBySession.delete(sid);
|
|
@@ -824,9 +919,17 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
824
919
|
state.labels[node.id] = node.label;
|
|
825
920
|
if (!outcome.ok) {
|
|
826
921
|
state.failed[node.id] = { id: node.id, label: node.label, reason: outcome.reason || 'unknown' };
|
|
922
|
+
if (outcome.reason === 'activation-failed') activationFailCount += 1;
|
|
827
923
|
} else if (outcome.empty) {
|
|
828
924
|
state.emptyOutputs[node.id] = { id: node.id, label: node.label };
|
|
829
925
|
}
|
|
926
|
+
if (isPermissionFailure(outcome)) {
|
|
927
|
+
permBlocked.push(node.label || node.id);
|
|
928
|
+
haltedReason = '检测到权限/沙箱受限导致节点失败(' + permBlocked.join('、')
|
|
929
|
+
+ '),已熔断停止启动后续节点以防继续消耗额度。请先检查主对话左下角权限模式,放开后重新运行。';
|
|
930
|
+
} else if (activationFailCount >= 2 && !haltedReason) {
|
|
931
|
+
haltedReason = '连续 ' + activationFailCount + ' 个子代理启动失败,已熔断停止后续节点以防继续消耗额度。请检查模型配置或主对话权限后重试。';
|
|
932
|
+
}
|
|
830
933
|
state.done.add(node.id);
|
|
831
934
|
continue;
|
|
832
935
|
}
|
|
@@ -1256,6 +1359,8 @@ export function apply(ctx) {
|
|
|
1256
1359
|
leadResult: { type: 'string', description: 'Your own output for the Lead step that was just requested.' },
|
|
1257
1360
|
task: { type: 'string', description: 'Optional overall task overriding the entry Lead task for this run (useful for reusing a preset).' },
|
|
1258
1361
|
reset: { type: 'boolean', description: 'Discard any paused run progress and start from the beginning.' },
|
|
1362
|
+
clearMemory: { type: 'boolean', description: 'Forget saved subagent sessions (keepSession memory) for this session before running so every node starts fresh.' },
|
|
1363
|
+
maxParallel: { type: 'integer', minimum: 1, maximum: 8, description: 'Optional concurrency limit override (1–8, default 4).' },
|
|
1259
1364
|
},
|
|
1260
1365
|
additionalProperties: false,
|
|
1261
1366
|
},
|
|
@@ -1362,6 +1467,7 @@ export {
|
|
|
1362
1467
|
inspectPlan,
|
|
1363
1468
|
sessionIdFromContext,
|
|
1364
1469
|
buildActiveCanvasContext,
|
|
1470
|
+
isPermissionFailure,
|
|
1365
1471
|
runPlan,
|
|
1366
1472
|
executePlan,
|
|
1367
1473
|
};
|
package/package.json
CHANGED
|
@@ -50,7 +50,9 @@ Links only join matching types. Nodes the entry Lead cannot reach are skipped at
|
|
|
50
50
|
## Running
|
|
51
51
|
|
|
52
52
|
1. The canvas must be enabled (the pill over the canvas); `canvas_workflow` refuses while it is disabled. While enabled, the host automatically injects a per-session runtime context reminder on each turn.
|
|
53
|
-
2. You may pass `task` to override the entry Lead's task (handy when reusing a preset),
|
|
53
|
+
2. You may pass `task` to override the entry Lead's task (handy when reusing a preset), `reset: true` to discard a paused run and start from scratch, and `clearMemory: true` to forget saved `keepSession` child sessions so every node starts fresh.
|
|
54
|
+
3. Solo chained Lead nodes (zero subagent upstream) and dangling dead-end subagents (zero outgoing edges while an active downstream Lead exists) are rendered dashed on the canvas and skipped at run time. Wiring a Lead + Subagent together into a downstream Lead is valid and active.
|
|
55
|
+
4. Subagent capability (`preset: standard | minimal`) narrows the toolset within the main chat's permission ceiling; it cannot elevate past the parent session's sandbox/approval mode.
|
|
54
56
|
3. Subagent nodes run in a dynamic concurrency pool of up to four: as soon as any node finishes, newly unblocked downstream subagents start immediately without waiting for slower siblings.
|
|
55
57
|
4. Intermediate downstream Lead nodes pause the run (`status: "need-lead"`). Complete that Lead step yourself, then call `canvas_workflow` again with `leadResult` to resume downstream nodes — do not spawn an agent for it.
|
|
56
58
|
5. A **terminal** Lead node (zero remaining downstream nodes) finishes directly with `status: "done"` and `finalLead`: complete the review/summary and reply directly to the user — no extra `canvas_workflow` callback is needed.
|