dsh-workflow-canvas 1.4.0 → 1.5.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/docs/DETAIL.md CHANGED
@@ -10,34 +10,48 @@ are performed by the conversation itself.
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
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.
13
+ the node's child session (Latest or pinned past run); optional **Fallback**
14
+ retries once on another model.
14
15
  - **Lead node** (blue top bar): performed by the conversation, never spawned. The
15
16
  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.
17
+ decision; `Lead → Lead` stage chains are supported with zero subagent spawns
18
+ when `role` is filled; a terminal Lead finishes in one shot without an extra
19
+ callback.
17
20
  - **Condition node** (amber top bar): lightweight read-only (`minimal`) branch
18
21
  judge supporting inline-editable binary `if/else` (`Yes` / `No`), multi-way
19
22
  `switch/case` (`+ Case`), and `Single` / `Multi` match modes (including clean
20
23
  zero-match full skip when no branch applies). Unchosen paths are pruned
21
24
  automatically without spawning, and branches can converge back into a shared
22
25
  downstream node or terminal Lead.
23
- - **Typed outputs, universal input**: right-side output sockets pick the channel
26
+ - **Controlled retry loops (`↺`)**: wire a condition branch back to a strict
27
+ ancestor (or select connected nodes and right-click **`↺ Create loop`**,
28
+ auto-inserting a condition gate if the tail is a subagent). Loop members get a
29
+ color-coded outer dashed outline and outer bypass rail with a clickable `↺ ×N`
30
+ pill (`1–10` retries), resetting only loop members on retry, injecting failure
31
+ feedback with healthy warm-session reuse, and circuit-breaking to the nearest
32
+ Lead when exhausted.
33
+ - **Global & per-node `+ Refs`**: every node's top-right title bar supports up to
34
+ 16 reference paths, URLs, or rules automatically deduplicated and injected at
35
+ run time.
36
+ - **Typed outputs, universal input**: output sockets pick the channel
24
37
  (`prompt` / `structured` / `session` / condition branch); every non-entry node
25
- exposes a single universal left input (`in`) that accepts any wire and inherits
26
- the source colour. Cycles are blocked immediately; drag a connected input away
27
- to detach its latest wire.
28
- - Inactive nodes (unreachable from entry, solo chained Leads with no subagent
29
- upstream, or dangling dead-end subagents) are drawn dashed and skipped at run time.
30
- - Wheel zooms around the cursor; middle-drag (or `Space` + drag) pans; `⊡ Fit`
31
- fits all nodes into the visible viewport; the percentage button resets to 100%
32
- on the Lead.
33
- - Marquee selection: drag on empty canvas to select multiple nodes; dragging any
34
- selected node moves the whole selection.
35
- - Right-drag across links cuts them on release; the swept path and links about to
36
- be cut highlight in red (toggle under `⋯`).
37
- - Shortcuts: `Shift+A` opens the Add Node menu at the cursor,
38
- `Ctrl+D` duplicates selected nodes, `Delete` removes selected nodes, `Ctrl+Z`
39
- undoes, and `Esc` closes popups. `⋯` also provides `⊞ Auto layout`,
40
- `⇧ Copy JSON`, and `Visual effects` (`Minimal` / `Standard` / `Vivid`).
38
+ exposes a single universal input (`in`) that accepts any wire and inherits the
39
+ source colour. Arbitrary cycles are blocked immediately; drag a connected input
40
+ away to detach its latest forward wire.
41
+ - Inactive nodes (unreachable from entry, blank-role solo chained Leads with no
42
+ subagent upstream, or dangling dead-end subagents) are drawn dashed and skipped
43
+ at run time.
44
+ - **Horizontal / vertical layout & slim narrow-sidebar UI**: toggle `⇄ Horiz` /
45
+ `⇅ Vert` (top-in / bottom-out curves + condition `Out R / Out L`); right-click
46
+ any node, edge, or blank canvas for context actions (insert on wire, create
47
+ loop, duplicate/delete, layout, undo/redo) without conflicting with right-drag
48
+ wire cutting (`>= 6px`). Bottom-right floating `⊡ | 100%` pill handles fit and
49
+ scrub zoom.
50
+ - **Multi-select & customizable shortcuts**: marquee drag or `Shift`/`Ctrl`+click
51
+ to multi-select; `Shift+A` adds at cursor, `Shift+D` duplicates selected nodes
52
+ together with internal wires, `Delete` removes selected, `Ctrl+Z` /
53
+ `Ctrl+Shift+Z` (`Ctrl+Y`) undo/redo, and `Esc` closes popups. Customize bindings
54
+ under `⋯ → ⌨ Shortcuts`.
41
55
  - Click any subagent node's status pill (e.g. `Done ↗`) to jump straight to its
42
56
  live subagent chat pane.
43
57
 
@@ -76,8 +90,9 @@ if the Host refuses, the record is dropped and the node starts fresh.
76
90
 
77
91
  - Saved presets live in browser storage and do not auto-sync between the Desktop
78
92
  app and `dsh web`, nor across machines (use `⋯ → ⇧ Copy JSON` and `⇩ Import`
79
- to share or migrate them; starter templates are built in under `☰ Presets`).
80
- - Lead steps have no tracked state; they show **Runs in chat** (or **Ready** once all upstream subagents finish).
81
- - Up to 4 nodes run at a time.
93
+ to share or migrate them; 5 starter templates including conditional branching &
94
+ retry loop are built in under `☰ Presets`).
95
+ - Lead steps have no child session; they show **Runs in chat** (or **Ready** once upstream finishes).
96
+ - Concurrency defaults to 4 (configurable 1–8 under `⋯`); controlled loops allow up to 1–10 retries per loop (20 global safety cap).
82
97
 
83
98
  For architecture diagrams and runtime internals, see [MECHANISM.md](MECHANISM.md) ([中文](MECHANISM.zh.md)).
package/docs/MECHANISM.md CHANGED
@@ -60,14 +60,15 @@ flowchart LR
60
60
  When `canvas_workflow` runs, `executePlan` executes the following pipeline:
61
61
 
62
62
  1. **Entry stripping & task override**: The entry `lead` node is stripped (`withoutEntry`) and never spawned. If `args.task` is provided, it overrides `plan.task` for this run (allowing blank-task templates to be reused straight from chat).
63
- 2. **Cycle validation (Kahn topological sort)**: `orderNodes` validates the DAG is acyclic (the client also blocks cycles interactively via `wouldCycle`).
64
- 3. **Reachability pruning**: BFS from `'lead'` filters out disconnected nodes. Unreachable nodes are drawn dashed, skipped at run time, and listed in `skipped` without burning tokens.
65
- 4. **Event-driven concurrency pool, conditional pruning & partial resume**:
63
+ 2. **DAG & controlled-loop validation**: `orderNodes` validates forward edges (`!e.loop`) via Kahn topological sort; `validateLoopEdges` separately verifies controlled retry edges (`e.loop === true`) leave a condition node, target a strict forward ancestor (never entry Lead), and do not overlap/cross.
64
+ 3. **Reachability & inactive pruning**: BFS from `'lead'` over forward edges filters out disconnected nodes, blank-role solo chained Leads without subagent upstream, and dangling dead-end subagents; all render dashed and are listed in `skipped` without burning tokens.
65
+ 4. **Event-driven concurrency pool, conditional pruning, retry loops & partial resume**:
66
66
  - In-progress state lives in `runBySession`, and each completed or halted run is snapshotted into `lastRunBySession`.
67
67
  - Instead of a strict per-wave barrier, the executor runs an **event-driven concurrency pool (`inFlight` + `Promise.race`, default 4, configurable 1–8)**:
68
68
  - The instant any running subagent finishes, newly unblocked downstream subagents launch immediately — fast branches never stall waiting for slower siblings.
69
69
  - **Condition nodes (`kind: "condition"`)** run as lightweight read-only (`minimal`) judges with a strict structured `outputSchema` (supporting binary `if/else`, multi-way `switch/case`, and `multiMatch` parallel fan-out). Unmatched outgoing edges are blocked and unchosen branches are pruned via ancestor-aware BFS (so an upstream `session-ref` side wire cannot bypass a vetoed branch). If zero branches match or the condition node itself fails, it never guesses a branch — it skips intermediate branches and hands off to the nearest downstream Lead (or halts cleanly if none exists).
70
- - Intermediate **non-entry Lead nodes** pause with `status: "need-lead"`; a **terminal Lead** (zero remaining downstream work) finishes in one shot with `status: "done"` and `finalLead`.
70
+ - **Controlled retry loops (`loop: true, maxIterations: 1–10`)**: when a condition matches a loop back-edge (taking priority over forward branches under `multiMatch`), if within per-loop and global safety limits (`20`), the executor resets strictly `descendants(target) ∩ ancestors(source)` (bypass nodes outside the loop never re-run), injects the rejection reason into the entry node (supporting both subagents and Lead nodes), and reuses its healthy warm session with an incremental correction prompt (or starts fresh if the prior round crashed/returned empty). At the limit, it circuit-breaks and hands off `1..N` round summaries to the nearest downstream Lead.
71
+ - Intermediate **non-entry Lead nodes** (including `Lead → Lead` stage chains) pause with `status: "need-lead"`; a **terminal Lead** (zero remaining downstream work) finishes in one shot with `status: "done"` and `finalLead`.
71
72
  - **`retryFailed: true`** and **`fromNodes: [...]`** reuse succeeded outputs from `lastRunBySession` and re-run only failed/target nodes plus their downstream; `reset: true` discards progress and starts from scratch.
72
73
 
73
74
  ```mermaid
@@ -121,7 +122,7 @@ The three link types are distinct runtime channels, not just visual colour codin
121
122
  ## 5. Live Status Pills & Click-to-Open Subagent Chats
122
123
 
123
124
  1. **Node tagging**: `spawnOnce` tags every spawned child with `label: "<node.label>#<node.id>"`.
124
- 2. **Catalog projection tracking**: While a turn runs (every 700ms, plus on mount and turn completion), the client reads `subagentCatalog` and `subagentTiming` from `sessions.list`, matching `/#([^\s#]+)$/` to map each child back to its canvas node (`running` / `done` / `failed`) and latest `childId`.
125
+ 2. **Catalog & run-state telemetry tracking**: While a turn runs (every 700ms, plus on mount and turn completion), the client reads `subagentCatalog` and `subagentTiming` from `sessions.list`, matching `/#([^\s#]+)$/` to map each child back to its canvas node (`running` / `done` / `failed`) and latest `childId`, while also polling `<workspace>/.dsh/canvas/<sid>.run.json` for condition `decisions`, `pruned` nodes, `blockedEdges`, live retry counts (`loopCounts` / `nodeAttempts`), and `waitingLead`.
125
126
  3. **Lead `⏸ Ready` detection**: For non-entry Lead nodes, the client highlights **`⏸ Ready`** as soon as all upstream subagents are `done` and no downstream node has started yet.
126
127
  4. **Jump to live chat**: Clicking any subagent's bottom-left status pill (e.g. `Running ↗`, `Done ↗`) opens `dsh-resource://subagentchat/session/<childId>?parent=<sessionId>&mode=<mode>` via `sidebarRight.openResource(..., { kind: 'subagentchat', preferNewPane: true })`.
127
128
 
@@ -57,14 +57,15 @@ flowchart LR
57
57
  调用 `canvas_workflow` 时,Host 的 `executePlan` 按以下流水线运行:
58
58
 
59
59
  1. **入口剥离与任务解析**:剥离作为总任务容器的入口节点 `lead`(永不作为子代理执行)。若调用时传入 `task` 参数,则覆盖入口 Lead 的总任务(方便直接复用空任务预设)。
60
- 2. **成环校验(Kahn 拓扑排序)**:用 `orderNodes` 校验 DAG 无环(客户端手动画线时也会用 `wouldCycle` 即时拦截)。
61
- 3. **可达性剪枝**:从入口 `lead` 做广度优先遍历,不可达的孤立节点在画布上显示为虚线,运行时被自动跳过并列入 `skipped`,不会消耗 Token。
62
- 4. **事件驱动并发池、条件剪枝与断点续跑**:
60
+ 2. **成环校验与受控回环校验**:`orderNodes` 在**前向边(`!e.loop`)**上用 Kahn 拓扑排序保证主图无环;`validateLoopEdges` 单独校验受控回环边(`e.loop === true`),要求起点必为条件节点、目标必为严格前向祖先(非入口 Lead)且回环互不交叉。
61
+ 3. **可达性剪枝**:从入口 `lead` 沿前向边做广度优先遍历,不可达的孤立节点、空分工且无子代理上游的 Lead、以及悬空无出边的子代理在画布上显示为虚线,运行时自动跳过并列入 `skipped`,不会消耗 Token。
62
+ 4. **事件驱动并发池、条件剪枝、受控回环与断点续跑**:
63
63
  - 每个会话的运行进度保存在 `runBySession`,每次结束/熔断还会将快照存入 `lastRunBySession`;
64
64
  - 执行器维护一个**可调并发上限**(默认 4,可在 `⋯` 菜单或参数中调为 `1–8`)的**动态并发池(`inFlight` + `Promise.race`)**:
65
65
  - 只要有任意在跑子代理完成、空出并发槽位,**任何依赖已满足的下游子代理会立刻启动**,不再傻等同层较慢的兄弟节点;
66
66
  - 遇到**条件节点(`kind: "condition"`)**时,以轻量只读模式(`minimal`)+ 严格结构化 `outputSchema` 判断命中分支(支持默认 `if/else`、任意多路 `switch/case` 单选与 `multiMatch` 多选并行),随即阻断未命中出边并用祖先感知 BFS 剪枝未命中分支(包括防止上游 `session-ref` 侧线绕过条件);若所有分支均未命中或条件节点自身失败,则绝不瞎猜分支,直接跳过中间分支转交最近下游 Lead(无下游 Lead 时熔断暂停);
67
- - 遇到**中间 Lead 节点**时暂停并返回 `status: "need-lead"`;遇到**末尾终审 Lead**(无剩余下游)时直接一步返回 `status: "done"` 与 `finalLead`,无需多余回调轮次;
67
+ - 遇到命中的**受控回环边(`loop: true, maxIterations: 1–10`)**时(`multiMatch` 下回环优先):若未超单环上限与全局安全上限(`20` 次),精准重置 `descendants(入口) ∩ ancestors(条件)` 环内节点的运行状态(环外旁路不受影响),把打回理由注入回环入口(同时支持子代理与 `Lead` 节点),并在入口上一轮执行健康时自动复用其热子会话发送增量修正提示词(崩溃/空输出则丢弃旧会话重开);若达到上限则熔断停止回跳,汇总 `1..N` 轮失败理由转交最近下游 Lead 拍板;
68
+ - 遇到**中间 Lead 节点**(支持 `Lead → Lead` 阶段串联)时暂停并返回 `status: "need-lead"`;遇到**末尾终审 Lead**(无剩余下游)时直接一步返回 `status: "done"` 与 `finalLead`,无需多余回调轮次;
68
69
  - 支持 **`retryFailed: true`** 或 **`fromNodes: [...]`** 局部重跑:自动复用上次已成功节点的缓存结果,仅重跑失败/目标节点及其下游;传 `reset: true` 则从头重跑。
69
70
 
70
71
  ```mermaid
@@ -118,7 +119,7 @@ sequenceDiagram
118
119
  ## 5. 实时状态胶囊与点击直达子会话
119
120
 
120
121
  1. **节点反查标记**:`spawnOnce` 启动子代理时,固定把 `spec.label` 设为 `<节点名>#<nodeId>`。
121
- 2. **状态实时追踪**:客户端监听当前会话的运行态,在对话运行期间每 700ms(以及挂载与每轮结束时)读取 `sessions.list` 投影中的 `subagentCatalog` 与 `subagentTiming`,用末尾正则 `/#([^\s#]+)$/` 精准反查节点状态(`running` / `done` / `failed`)以及对应的 `childId`。
122
+ 2. **状态与遥测实时追踪**:客户端在对话运行期间每 700ms(以及挂载与每轮结束时)读取 `sessions.list` 投影中的 `subagentCatalog` 与 `subagentTiming`,用末尾正则 `/#([^\s#]+)$/` 精准反查子代理状态(`running` / `done` / `failed`)与 `childId`;同时轮询 Host 写入的 `<workspace>/.dsh/canvas/<sid>.run.json` 获取条件判决(`decisions`)、剪枝集(`pruned`)、阻断边(`blockedEdges`)、回环实时轮次(`loopCounts` / `nodeAttempts`)与待拍板状态(`waitingLead`)。
122
123
  3. **Lead「待拍板」自动高亮**:对于非入口 Lead 节点,客户端检测到其所有上游子代理均为 `done` 且下游尚未启动时,自动亮起蓝色 **`⏸ 待拍板`** 提示。
123
124
  4. **一键直达真实子对话**:点击任意子代理节点左下角状态胶囊(如 `进行中 ↗` / `已完成 ↗`),客户端调用 `sidebarRight.openResource('dsh-resource://subagentchat/session/<childId>?parent=<sessionId>&mode=<mode>', { kind: 'subagentchat', preferNewPane: true })`,直接在新侧边窗格打开该子代理的真实对话记录。
124
125
 
Binary file
Binary file