dsh-workflow-canvas 1.0.1 → 1.0.2
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/index.js +100 -4
- package/package.json +1 -1
- package/skills/workflow-canvas/SKILL.md +1 -1
package/index.js
CHANGED
|
@@ -24,6 +24,8 @@ 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
|
+
/** Snapshot of the last completed/halted run per Session id (enables partial retry). */
|
|
28
|
+
const lastRunBySession = new Map();
|
|
27
29
|
/**
|
|
28
30
|
* Two separate maps by design:
|
|
29
31
|
* - `childByNode`: persisted memory slot written ONLY when `keepSession` is ON,
|
|
@@ -768,6 +770,17 @@ function buildActiveCanvasContext(sid) {
|
|
|
768
770
|
if (stdCount >= 2) {
|
|
769
771
|
lines.push('- 本画布包含 ' + stdCount + ' 个可写/命令型(standard)子代理,受主对话权限上限约束;若任务涉及改代码、写文件或跑终端命令且当前主对话权限偏严格,请先简短提醒用户放开主对话权限再调 `canvas_workflow`,避免中途报错白耗额度。');
|
|
770
772
|
}
|
|
773
|
+
const prevRun = lastRunBySession.get(String(sid));
|
|
774
|
+
if (prevRun) {
|
|
775
|
+
const badNames = [
|
|
776
|
+
...Object.values(prevRun.failed || {}).map((f) => f.label || f.id),
|
|
777
|
+
...Object.values(prevRun.emptyOutputs || {}).map((e) => e.label || e.id),
|
|
778
|
+
].filter((v, i, arr) => v && arr.indexOf(v) === i);
|
|
779
|
+
if (prevRun.halted || badNames.length) {
|
|
780
|
+
lines.push('- 上次运行存在失败/熔断节点(' + (badNames.join('、') || '部分未完成')
|
|
781
|
+
+ '):若用户要求只重跑失败部分或继续未完成段,请调用 `canvas_workflow({ retryFailed: true })` 局部续跑(自动复用已成功节点缓存,零重复消耗);也可传 `fromNodes: ["节点id"]` 指定从某个节点开始重跑。');
|
|
782
|
+
}
|
|
783
|
+
}
|
|
771
784
|
return lines.join('\n');
|
|
772
785
|
}
|
|
773
786
|
|
|
@@ -823,18 +836,87 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
823
836
|
}
|
|
824
837
|
if (opts.reset === true && sid) {
|
|
825
838
|
runBySession.delete(sid);
|
|
839
|
+
lastRunBySession.delete(sid);
|
|
826
840
|
}
|
|
827
841
|
|
|
842
|
+
const byId = new Map(runnable.map((n) => [n.id, n]));
|
|
843
|
+
const labelOf = new Map(order.map((n) => [n.id, n.label || n.id]));
|
|
828
844
|
const sig = JSON.stringify(plan);
|
|
829
845
|
let state = runBySession.get(sid);
|
|
846
|
+
const wantRetryFailed = opts.retryFailed === true;
|
|
847
|
+
const rawFromNodes = Array.isArray(opts.fromNodes) ? opts.fromNodes.filter((x) => typeof x === 'string' && x.trim()) : [];
|
|
848
|
+
const wantPartial = wantRetryFailed || rawFromNodes.length > 0;
|
|
849
|
+
let reused = [];
|
|
850
|
+
|
|
851
|
+
if (wantPartial && sid) {
|
|
852
|
+
const base = state || lastRunBySession.get(sid);
|
|
853
|
+
if (base) {
|
|
854
|
+
state = {
|
|
855
|
+
sig,
|
|
856
|
+
done: new Set(Array.from(base.done || []).filter((id) => byId.has(id))),
|
|
857
|
+
results: { ...(base.results || {}) },
|
|
858
|
+
labels: { ...(base.labels || {}) },
|
|
859
|
+
failed: { ...(base.failed || {}) },
|
|
860
|
+
emptyOutputs: { ...(base.emptyOutputs || {}) },
|
|
861
|
+
waitingLead: null,
|
|
862
|
+
};
|
|
863
|
+
// Build forward adjacency to invalidate seed nodes and all their downstream dependents.
|
|
864
|
+
const fwd = new Map();
|
|
865
|
+
for (const e of plan.edges || []) {
|
|
866
|
+
if (!e || !e.from || !e.to) continue;
|
|
867
|
+
if (!fwd.has(e.from)) fwd.set(e.from, []);
|
|
868
|
+
fwd.get(e.from).push(e.to);
|
|
869
|
+
}
|
|
870
|
+
const seeds = new Set();
|
|
871
|
+
if (wantRetryFailed) {
|
|
872
|
+
for (const id of Object.keys(state.failed)) seeds.add(id);
|
|
873
|
+
for (const id of Object.keys(state.emptyOutputs)) seeds.add(id);
|
|
874
|
+
}
|
|
875
|
+
for (const ref of rawFromNodes) {
|
|
876
|
+
const trimmed = ref.trim();
|
|
877
|
+
if (byId.has(trimmed)) seeds.add(trimmed);
|
|
878
|
+
else {
|
|
879
|
+
const match = runnable.find((n) => n.label === trimmed);
|
|
880
|
+
if (match) seeds.add(match.id);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
const invalid = new Set(seeds);
|
|
884
|
+
const q = Array.from(seeds);
|
|
885
|
+
for (let i = 0; i < q.length; i += 1) {
|
|
886
|
+
for (const next of fwd.get(q[i]) || []) {
|
|
887
|
+
if (!invalid.has(next)) { invalid.add(next); q.push(next); }
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
for (const id of invalid) {
|
|
891
|
+
state.done.delete(id);
|
|
892
|
+
delete state.results[id];
|
|
893
|
+
delete state.labels[id];
|
|
894
|
+
delete state.failed[id];
|
|
895
|
+
delete state.emptyOutputs[id];
|
|
896
|
+
}
|
|
897
|
+
reused = Array.from(state.done).map((id) => labelOf.get(id) || id);
|
|
898
|
+
runBySession.set(sid, state);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
830
902
|
if (!state || state.sig !== sig) {
|
|
831
903
|
state = { sig, done: new Set(), results: {}, labels: {}, failed: {}, emptyOutputs: {}, waitingLead: null };
|
|
832
904
|
runBySession.set(sid, state);
|
|
833
905
|
}
|
|
834
906
|
if (!state.emptyOutputs) state.emptyOutputs = {};
|
|
835
907
|
|
|
836
|
-
const
|
|
837
|
-
|
|
908
|
+
const snapshotLastRun = (haltedFlag) => {
|
|
909
|
+
if (!sid) return;
|
|
910
|
+
lastRunBySession.set(sid, {
|
|
911
|
+
sig: state.sig,
|
|
912
|
+
done: new Set(state.done),
|
|
913
|
+
results: { ...state.results },
|
|
914
|
+
labels: { ...state.labels },
|
|
915
|
+
failed: { ...state.failed },
|
|
916
|
+
emptyOutputs: { ...state.emptyOutputs },
|
|
917
|
+
halted: Boolean(haltedFlag),
|
|
918
|
+
});
|
|
919
|
+
};
|
|
838
920
|
const depsOf = (node) => (plan.edges || [])
|
|
839
921
|
.filter((e) => e.to === node.id && e.from !== 'lead')
|
|
840
922
|
.map((e) => e.from)
|
|
@@ -880,20 +962,23 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
880
962
|
// but let already in-flight siblings settle so no orphan promises or partial
|
|
881
963
|
// results are dropped before returning the halted report.
|
|
882
964
|
if (haltedReason && inFlight.size === 0) {
|
|
965
|
+
snapshotLastRun(true);
|
|
883
966
|
if (sid) runBySession.delete(sid);
|
|
884
967
|
saveStore();
|
|
885
968
|
return {
|
|
886
969
|
status: 'halted',
|
|
887
|
-
error: haltedReason,
|
|
970
|
+
error: haltedReason + '(放开权限后可调用 canvas_workflow({ retryFailed: true }) 只重跑失败与未完成节点)',
|
|
888
971
|
results: state.results,
|
|
889
972
|
labels: state.labels,
|
|
890
973
|
failed: Object.values(state.failed),
|
|
891
974
|
emptyOutputs: Object.values(state.emptyOutputs),
|
|
975
|
+
reused,
|
|
892
976
|
skipped,
|
|
893
977
|
};
|
|
894
978
|
}
|
|
895
979
|
const remaining = runnable.filter((n) => !state.done.has(n.id));
|
|
896
980
|
if (!remaining.length) {
|
|
981
|
+
snapshotLastRun(false);
|
|
897
982
|
runBySession.delete(sid);
|
|
898
983
|
saveStore();
|
|
899
984
|
return {
|
|
@@ -902,6 +987,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
902
987
|
labels: state.labels,
|
|
903
988
|
failed: Object.values(state.failed),
|
|
904
989
|
emptyOutputs: Object.values(state.emptyOutputs),
|
|
990
|
+
reused,
|
|
905
991
|
skipped,
|
|
906
992
|
};
|
|
907
993
|
}
|
|
@@ -951,6 +1037,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
951
1037
|
if (!hasDownstreamWork && leadResult === undefined) {
|
|
952
1038
|
// Terminal Lead: zero downstream nodes remain, so complete the run directly
|
|
953
1039
|
// and hand off final review/delivery to the Lead without a redundant extra turn.
|
|
1040
|
+
snapshotLastRun(false);
|
|
954
1041
|
if (sid) runBySession.delete(sid);
|
|
955
1042
|
saveStore();
|
|
956
1043
|
return {
|
|
@@ -965,6 +1052,7 @@ async function executePlan(scope, plan, args, exec) {
|
|
|
965
1052
|
failed: Object.values(state.failed),
|
|
966
1053
|
emptyOutputs: Object.values(state.emptyOutputs),
|
|
967
1054
|
sessions: leadSessions,
|
|
1055
|
+
reused,
|
|
968
1056
|
skipped,
|
|
969
1057
|
hint: '所有子代理已完成。最后一步由你(Lead 本体)按要求完成终审/汇总后直接向用户交付即可,无需再次调用 canvas_workflow。',
|
|
970
1058
|
};
|
|
@@ -1196,6 +1284,7 @@ export function apply(ctx) {
|
|
|
1196
1284
|
},
|
|
1197
1285
|
});
|
|
1198
1286
|
runBySession.delete(sid);
|
|
1287
|
+
lastRunBySession.delete(sid);
|
|
1199
1288
|
saveStore();
|
|
1200
1289
|
}
|
|
1201
1290
|
return { canvas, delivered, warnings };
|
|
@@ -1359,6 +1448,8 @@ export function apply(ctx) {
|
|
|
1359
1448
|
leadResult: { type: 'string', description: 'Your own output for the Lead step that was just requested.' },
|
|
1360
1449
|
task: { type: 'string', description: 'Optional overall task overriding the entry Lead task for this run (useful for reusing a preset).' },
|
|
1361
1450
|
reset: { type: 'boolean', description: 'Discard any paused run progress and start from the beginning.' },
|
|
1451
|
+
retryFailed: { type: 'boolean', description: 'Reuse succeeded nodes from the previous run and re-run only failed, empty, or unfinished nodes along with their downstream.' },
|
|
1452
|
+
fromNodes: { type: 'array', items: { type: 'string' }, description: 'Re-run only the specified node ids (or labels) and their downstream, reusing all other succeeded nodes from the previous run.' },
|
|
1362
1453
|
clearMemory: { type: 'boolean', description: 'Forget saved subagent sessions (keepSession memory) for this session before running so every node starts fresh.' },
|
|
1363
1454
|
maxParallel: { type: 'integer', minimum: 1, maximum: 8, description: 'Optional concurrency limit override (1–8, default 4).' },
|
|
1364
1455
|
},
|
|
@@ -1376,6 +1467,7 @@ export function apply(ctx) {
|
|
|
1376
1467
|
failed: { type: 'array' },
|
|
1377
1468
|
emptyOutputs: { type: 'array' },
|
|
1378
1469
|
sessions: { type: 'array' },
|
|
1470
|
+
reused: { type: 'array' },
|
|
1379
1471
|
skipped: { type: 'array' },
|
|
1380
1472
|
hint: { type: 'string' },
|
|
1381
1473
|
error: { type: 'string' },
|
|
@@ -1420,6 +1512,9 @@ export function apply(ctx) {
|
|
|
1420
1512
|
const skip = Array.isArray(v.skipped) && v.skipped.length
|
|
1421
1513
|
? '\n\n已跳过(未连线):' + v.skipped.join('、')
|
|
1422
1514
|
: '';
|
|
1515
|
+
const reusedNote = Array.isArray(v.reused) && v.reused.length
|
|
1516
|
+
? '\n\n已复用上次成功缓存(未重复消耗):' + v.reused.join('、')
|
|
1517
|
+
: '';
|
|
1423
1518
|
if (v.finalLead) {
|
|
1424
1519
|
const fl = v.finalLead;
|
|
1425
1520
|
const handed = Array.isArray(v.sessions) ? v.sessions.filter((s) => s && s.childId) : [];
|
|
@@ -1435,11 +1530,12 @@ export function apply(ctx) {
|
|
|
1435
1530
|
+ emptyList
|
|
1436
1531
|
+ '\n\n已完成节点的结果:\n' + body
|
|
1437
1532
|
+ handover
|
|
1533
|
+
+ reusedNote
|
|
1438
1534
|
+ skip
|
|
1439
1535
|
+ '\n\n' + (v.hint || ''),
|
|
1440
1536
|
}];
|
|
1441
1537
|
}
|
|
1442
|
-
return [{ type: 'text', text: '画布执行完成。' + failedList + emptyList + '\n\n' + body + skip }];
|
|
1538
|
+
return [{ type: 'text', text: '画布执行完成。' + failedList + emptyList + '\n\n' + body + reusedNote + skip }];
|
|
1443
1539
|
}
|
|
1444
1540
|
return [{ type: 'text', text: JSON.stringify(v) }];
|
|
1445
1541
|
},
|
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ 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), `reset: true` to discard a paused run and start from scratch, and `clearMemory: true` to forget saved `keepSession` child sessions
|
|
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, `retryFailed: true` to reuse succeeded nodes and re-run only failed/empty/unfinished nodes plus their downstream, `fromNodes: [...]` to re-run from specific node ids/labels, `clearMemory: true` to forget saved `keepSession` child sessions, and `maxParallel` (1–8) to adjust concurrency.
|
|
54
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
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.
|
|
56
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.
|