dsh-workflow-canvas 1.0.2 → 1.2.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
@@ -14,9 +14,17 @@ are performed by the conversation itself.
14
14
  - **Lead node** (blue top bar): performed by the conversation, never spawned. The
15
15
  entry node carries the overall task; intermediate Lead nodes pause for your
16
16
  decision, and a terminal Lead finishes in one shot without an extra callback.
17
- - **Sockets are typed** (`prompt` / `structured` / `session`); a link only joins
18
- the same type (either direction), and cycles are blocked immediately. Drag a
19
- connected input away to detach.
17
+ - **Condition node** (amber top bar): lightweight read-only (`minimal`) branch
18
+ judge supporting inline-editable binary `if/else` (`Yes` / `No`), multi-way
19
+ `switch/case` (`+ Case`), and `Single` / `Multi` match modes (including clean
20
+ zero-match full skip when no branch applies). Unchosen paths are pruned
21
+ automatically without spawning, and branches can converge back into a shared
22
+ downstream node or terminal Lead.
23
+ - **Typed outputs, universal input**: right-side output sockets pick the channel
24
+ (`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.
20
28
  - Inactive nodes (unreachable from entry, solo chained Leads with no subagent
21
29
  upstream, or dangling dead-end subagents) are drawn dashed and skipped at run time.
22
30
  - Wheel zooms around the cursor; middle-drag (or `Space` + drag) pans; `⊡ Fit`
@@ -47,13 +55,16 @@ node positions survive.
47
55
 
48
56
  ## Running
49
57
 
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`.
58
+ Subagent nodes run in an event-driven concurrency pool (default 4, configurable
59
+ 1–8 via `⋯` or `maxParallel`) via `canvas_workflow`, which supports `task`
60
+ (override the entry task for template reuse), `reset: true` (discard a paused
61
+ run), `retryFailed: true` / `fromNodes` (reuse succeeded nodes and re-run only
62
+ failed/target segments plus downstream), and `clearMemory: true` (forget saved
63
+ `keepSession` memories). While enabled, a per-session runtime context notifies
64
+ the agent automatically. Intermediate Lead nodes pause with `status: "need-lead"`
65
+ and report `decisions` / `branchSkipped` / `failed` / `emptyOutputs` plus
66
+ `session` handovers; a terminal Lead completes directly with `status: "done"`
67
+ and `finalLead`.
57
68
 
58
69
  ## Memory
59
70
 
package/docs/MECHANISM.md CHANGED
@@ -62,13 +62,13 @@ When `canvas_workflow` runs, `executePlan` executes the following pipeline:
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
63
  2. **Cycle validation (Kahn topological sort)**: `orderNodes` validates the DAG is acyclic (the client also blocks cycles interactively via `wouldCycle`).
64
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 & resumable pauses**:
66
- - Progress per session is tracked in `runBySession` (`{ sig, done, results, labels, failed }`).
67
- - Instead of a strict per-wave barrier, the executor runs an **event-driven concurrency pool (`inFlight` + `Promise.race`, `MAX_PARALLEL = 4`)**:
65
+ 4. **Event-driven concurrency pool, conditional pruning & partial resume**:
66
+ - In-progress state lives in `runBySession`, and each completed or halted run is snapshotted into `lastRunBySession`.
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
- - Once no runnable subagents remain and only downstream **non-entry Lead nodes** are ready (entry Lead never pauses) without a `leadResult`, execution pauses with `status: "need-lead"`, returning collected results, any failures, and `session` child IDs.
70
- - The conversation performs that Lead step and calls `canvas_workflow({ leadResult: "..." })` to resume seamlessly.
71
- - Changing the graph (different plan `sig`) or passing `reset: true` discards paused progress and restarts cleanly.
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`.
71
+ - **`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
72
 
73
73
  ```mermaid
74
74
  sequenceDiagram
@@ -123,7 +123,7 @@ The three link types are distinct runtime channels, not just visual colour codin
123
123
  1. **Node tagging**: `spawnOnce` tags every spawned child with `label: "<node.label>#<node.id>"`.
124
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
125
  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
- 4. **Jump to live chat**: Clicking any subagent's status pill (e.g. `Running ↗`, `Done ↗`) opens `dsh-resource://subagentchat/session/<childId>?parent=<sessionId>&mode=<mode>` via `sidebarRight.openResource(..., { kind: 'subagentchat', preferNewPane: true })`.
126
+ 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
127
 
128
128
  ---
129
129
 
@@ -59,13 +59,13 @@ flowchart LR
59
59
  1. **入口剥离与任务解析**:剥离作为总任务容器的入口节点 `lead`(永不作为子代理执行)。若调用时传入 `task` 参数,则覆盖入口 Lead 的总任务(方便直接复用空任务预设)。
60
60
  2. **成环校验(Kahn 拓扑排序)**:用 `orderNodes` 校验 DAG 无环(客户端手动画线时也会用 `wouldCycle` 即时拦截)。
61
61
  3. **可达性剪枝**:从入口 `lead` 做广度优先遍历,不可达的孤立节点在画布上显示为虚线,运行时被自动跳过并列入 `skipped`,不会消耗 Token。
62
- 4. **事件驱动并发池与暂停续跑**:
63
- - 每个会话的运行进度保存在 `runBySession`(包含计划签名 `sig`、`done`、`results`、`labels`、`failed`);
64
- - 执行器维护一个上限为 **4 并发**(`MAX_PARALLEL = 4`)的**动态并发池(`inFlight` + `Promise.race`)**,而非同步屏障:
62
+ 4. **事件驱动并发池、条件剪枝与断点续跑**:
63
+ - 每个会话的运行进度保存在 `runBySession`,每次结束/熔断还会将快照存入 `lastRunBySession`;
64
+ - 执行器维护一个**可调并发上限**(默认 4,可在 `⋯` 菜单或参数中调为 `1–8`)的**动态并发池(`inFlight` + `Promise.race`)**:
65
65
  - 只要有任意在跑子代理完成、空出并发槽位,**任何依赖已满足的下游子代理会立刻启动**,不再傻等同层较慢的兄弟节点;
66
- - 直到当前所有可执行子代理全部跑完、仅剩 **非入口 Lead 节点**就绪且尚未收到 `leadResult` 时,执行器暂停并返回 `status: "need-lead"`(入口 Lead 仅承载总任务,不会触发暂停),把已收集结果、失败汇总以及紫线 `childId` 交回主对话;
67
- - 主对话完成该 Lead 步骤后,再次调用 `canvas_workflow({ leadResult: "..." })`,执行器从断点无缝继续;
68
- - 若中途修改了画布(计划签名 `sig` 变化)或显式传入 `reset: true`,则丢弃旧进度从头重跑。
66
+ - 遇到**条件节点(`kind: "condition"`)**时,以轻量只读模式(`minimal`)+ 严格结构化 `outputSchema` 判断命中分支(支持默认 `if/else`、任意多路 `switch/case` 单选与 `multiMatch` 多选并行),随即阻断未命中出边并用祖先感知 BFS 剪枝未命中分支(包括防止上游 `session-ref` 侧线绕过条件);若所有分支均未命中或条件节点自身失败,则绝不瞎猜分支,直接跳过中间分支转交最近下游 Lead(无下游 Lead 时熔断暂停);
67
+ - 遇到**中间 Lead 节点**时暂停并返回 `status: "need-lead"`;遇到**末尾终审 Lead**(无剩余下游)时直接一步返回 `status: "done"` 与 `finalLead`,无需多余回调轮次;
68
+ - 支持 **`retryFailed: true`** 或 **`fromNodes: [...]`** 局部重跑:自动复用上次已成功节点的缓存结果,仅重跑失败/目标节点及其下游;传 `reset: true` 则从头重跑。
69
69
 
70
70
  ```mermaid
71
71
  sequenceDiagram
@@ -120,7 +120,7 @@ sequenceDiagram
120
120
  1. **节点反查标记**:`spawnOnce` 启动子代理时,固定把 `spec.label` 设为 `<节点名>#<nodeId>`。
121
121
  2. **状态实时追踪**:客户端监听当前会话的运行态,在对话运行期间每 700ms(以及挂载与每轮结束时)读取 `sessions.list` 投影中的 `subagentCatalog` 与 `subagentTiming`,用末尾正则 `/#([^\s#]+)$/` 精准反查节点状态(`running` / `done` / `failed`)以及对应的 `childId`。
122
122
  3. **Lead「待拍板」自动高亮**:对于非入口 Lead 节点,客户端检测到其所有上游子代理均为 `done` 且下游尚未启动时,自动亮起蓝色 **`⏸ 待拍板`** 提示。
123
- 4. **一键直达真实子对话**:点击任意子代理节点右下角状态胶囊(如 `进行中 ↗` / `已完成 ↗`),客户端调用 `sidebarRight.openResource('dsh-resource://subagentchat/session/<childId>?parent=<sessionId>&mode=<mode>', { kind: 'subagentchat', preferNewPane: true })`,直接在新侧边窗格打开该子代理的真实对话记录。
123
+ 4. **一键直达真实子对话**:点击任意子代理节点左下角状态胶囊(如 `进行中 ↗` / `已完成 ↗`),客户端调用 `sidebarRight.openResource('dsh-resource://subagentchat/session/<childId>?parent=<sessionId>&mode=<mode>', { kind: 'subagentchat', preferNewPane: true })`,直接在新侧边窗格打开该子代理的真实对话记录。
124
124
 
125
125
  ---
126
126
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file