@sshirkit/dsh-orchestrator 0.0.0-stage → 0.8.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SShiRkiT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,164 @@
1
+ <div align="center">
2
+
3
+ ##### Start from 28th October
4
+
5
+ <div align="center">
6
+
7
+ # DSH Orchestrator
8
+
9
+ </div>
10
+
11
+
12
+ #### **A powerful model plans, low-cost models do the work — the dispatch mode plugin with hard tool isolation for DeepSeek Harness**
13
+
14
+ [![version](https://img.shields.io/badge/version-0.8.4-4176E6?style=flat-square)](https://github.com/SShiRkiT/dsh-orchestrator)
15
+ [![dsh-plugin](https://img.shields.io/badge/DeepSeek%20Harness-dsh--plugin-4176E6?style=flat-square)](https://github.com/deepseek-ai/deepseek-harness)
16
+ [![platform](https://img.shields.io/badge/platform-Web%20GUI%20%7C%20Desktop-5c6bc0?style=flat-square)](https://github.com/SShiRkiT/dsh-orchestrator)
17
+ [![node](https://img.shields.io/badge/node-%3E%3D22-339933?style=flat-square&logo=nodedotjs&logoColor=white)](https://nodejs.org)
18
+ [![module](https://img.shields.io/badge/module-ESM-F7DF1E?style=flat-square&logo=javascript&logoColor=black)](package.json)
19
+ [![license](https://img.shields.io/badge/license-MIT-2ea44f?style=flat-square)](LICENSE)
20
+ [![GitHub stars](https://img.shields.io/github/stars/SShiRkiT/dsh-orchestrator?style=flat-square&logo=github)](https://github.com/SShiRkiT/dsh-orchestrator/stargazers)
21
+
22
+ [简体中文](README.md) | **English** · [Key differences](#why-do-you-need-this-plugin-alongside-native-subagent-and-agent-team) · [Core Features](#core-features) · [Installation](#installation) · [Configuration](#configuration)
23
+
24
+ </div>
25
+
26
+ ---
27
+ <div align="center">
28
+
29
+ ### Why Do You Need This Plugin Alongside Native `subagent` and `Agent Team`?
30
+ </div>
31
+ DSH includes native `subagent` / `workflow` tools, and the official `@deepseek-ai/dsh-experimental-agent-team-profile` (Agent Team) is also available. However, intensive development still exposes three pain points — the problems at the heart of **DSH Orchestrator**'s distinctive design:
32
+
33
+ | Pain point | Native `subagent` / official `Agent Team` | DSH Orchestrator (unique to this plugin) |
34
+ | --- | --- | --- |
35
+ | **The main agent keeps doing the work itself** | **Relies on compliance with soft prompts**: the main agent / Team Lead still has the full set of tools, including `read`, `edit`, and `bash`. After a few turns, it often starts reading files and running commands itself, quickly filling the main context. | **Whitelist-Driven Hard Gate**: the main agent receives only 12 core planning and delegation tools by default (`allowedTools`). All other host file and terminal tools, plus any future MCP or third-party plugin tools, are automatically hidden and blocked at execution time (including nested calls through `run_code`), **enforcing a Main Agent dedicated entirely to planning and acceptance, with Subagents doing all the execution**. |
36
+ | **Low-cost models get stuck or go off track** | **Runtime black box**: after dispatch, you can only wait for completion or timeout, or block and poll with `wait_agent`. | **Periodic background inspection of event logs + dynamic correction by the powerful model**: a background timer reads running Workers' session event logs directly (reading and summarizing make no model calls), summarizing elapsed time, rounds, new tool calls, and the latest output. A lightweight notice wakes the main agent when something looks abnormal or takes too long, so the powerful model can assess it and give targeted corrections. |
37
+ | **Large batches of similar tasks** | Native `workflow` asks the model to write arbitrary JavaScript, which can get out of control and does not enforce consistent model routing. | **Declarative `orchestrate` pipelines**: structured `items × stages` fan-out and multistage pipelines, with per-item failure isolation and strict JSON Schema validation. Every Worker is forced onto the low-cost subagent route. |
38
+
39
+ ---
40
+ <div align="center">
41
+
42
+ ## Core Features
43
+ </div>
44
+
45
+ ### 1. A powerful Main Agent and low-cost Subagents (independent panel, immediate updates)
46
+
47
+ In the dedicated **Dispatch mode panel** below the composer, the main-agent and subagent model routes are fully independent:
48
+ - **Main Agent**: choose your strongest flagship model (such as `gpt-astra-6` or `claude-opus-5.5`) to focus on clarifying requirements, splitting tasks, correcting course, and accepting final results.
49
+ - **Subagent**: choose a slightly less capable but very inexpensive model with high throughput (such as `deepseek-v4.1-flash` or `gpt-luna-6`). **Every Worker launched through `delegate` or `orchestrate` must share this low-cost route**, unless the user explicitly names a different model for temporary use in the current message.
50
+ - **Anti-burn protection**: dispatch fails with an error if no subagent model is configured
51
+
52
+ ![Dispatch Mode Panel](docs/images/dispatch-panel.png)
53
+
54
+ ### 2. A hard whitelist gate: the main agent plans and accepts results; subagents execute
55
+
56
+ Instead of relying on prompts asking the main model to use subagents more often, the plugin installs two guards at DSH's tool-definition outlet (`tools.definitions`) and execution layer (`tools.guard`), using a **whitelist-driven** approach. The definition layer trims the tool table visible to the model in real time, treating global tools and tools in scopes such as `ops_*` equally; the execution layer rejects any calls that slip through. Both layers read the current configuration on every request or call, without creating `tools.restrict` event storms, avoiding tool-visibility churn and prompt-cache invalidation from the official tool-hiding mechanism.
57
+ - **Main Agent stripped of all execution tools**:
58
+ <div align="center">
59
+
60
+ > ### DEFAULT_ALLOWED_TOOLS permits only 12 planning, delegation, and read-only session tools by default
61
+ >
62
+ > _`delegate`, `orchestrate`, `send_message`, `interrupt_agent`, `todo_write`, `ask_user_question`, `compress`, and five read-only session log tools._
63
+ >
64
+ > ### All file access, search, and terminal tools, plus any future MCP or third-party plugin tools, are automatically hidden and blocked at execution time
65
+ >
66
+ > _(`read` / `edit` / `write` / `apply_patch`), (`grep` / `glob`), (`bash` / `pwsh`), web fetching, and native `subagent` / `workflow`_
67
+ >
68
+ > ### Even nested calls through run_code are blocked. To allow additional tools, check them under Allowed Tools on the right of the panel.
69
+ </div>
70
+
71
+ - **Subagents retain the full toolchain**: dispatched Workers are exempt from the gate and read or write files, run tests, and inspect errors in their own contexts. When finished, they return only a concise conclusion for the main agent to review.
72
+ - **Switch at any time**: when the main agent needs to act directly, turn off Enable dispatch mode in the panel to restore all its tools immediately, without reopening the session.
73
+
74
+ ### 3. Periodic background inspection of event logs and correction by the powerful model
75
+
76
+ Low-cost Subagents can occasionally get stuck on complex shell escaping or errors. The plugin includes a background inspector driven entirely by logs:
77
+ - **Reading the logs makes no model calls**: a background timer directly reads running Workers' session event logs at the configured interval (600 seconds by default), summarizes elapsed time, rounds, new tool calls, and the latest output, then combines them into a notice that wakes the main agent. Reading and summarizing make no LLM requests
78
+ - However, **waking the Main Agent for judgment and steering still consumes Main Agent tokens**: supervision compresses continuous polling into one summary plus one decision; it does not make the entire supervision feature free.
79
+ - **The powerful model makes a quick assessment**: after receiving an inspection summary, the main agent needs only a small number of tokens to decide:
80
+ - **A) Progress is normal**: reply with one line, `巡检:正常`, and end the turn while the subagent continues.
81
+ - **B) Correct course**: call `send_message` to inject corrective instructions directly into the running subagent, specifying the right approach or telling it to skip a blocker.
82
+ - **C) Stop wasted work promptly**: call `interrupt_agent` to interrupt a subagent that has gone off track. If it is later reactivated with `send_message`, supervision automatically resumes and resets its notice count.
83
+
84
+ ![Example inspection notice and correction](docs/images/patrol-notice.png)
85
+
86
+ *Inspection and correction in practice: a low-cost subagent got stuck on shell quotes and backslash escaping. After a scheduled inspection woke the main agent, it supplied the correct syntax directly through `send_message` to get the worker back on track.*
87
+
88
+ ### 4. `delegate` and `orchestrate`, built for dispatch mode
89
+
90
+ - **`delegate` (asynchronous tasks on demand / parallel fan-out)**:
91
+ Dispatch self-contained, independent tasks (goal + allowed files + acceptance commands + fallback on failure). Multiple calls in the same turn start multiple Workers in parallel. The plugin injects a Simplified Chinese response instruction into every subagent's prompt and requires it to finish with a final summary in its reply, without calling `send_message` to report to its parent; the closing message is delivered to the main agent automatically.
92
+ **`writeScope` (required, `string[]`)**: declare the files or directories this worker may modify. Supported forms are exact files (`src/index.js`), directories (`dir/` or `dir/**`), and the global root (`*`). Relative paths are normalized lexically against `cwd`, with case-insensitive deduplication on Windows. Omitting the field produces `write-scope-missing`; an empty array or invalid path produces `write-scope-invalid`.
93
+ - **`orchestrate` (declarative batch pipelines)**:
94
+ Process a batch of items (`items`, 1–64) through a fixed set of stages (`stages`, 1–8), with `maxConcurrency` (1–16, default 4) controlling concurrency. Supports single-stage parallel fan-out and multistage **per-item pipelines without a global barrier**: an item enters stage 2 as soon as its stage 1 finishes, without waiting for slower items. Supports strict stage-level JSON Schema validation and per-item failure isolation.
95
+ **`writeScope` (required, `string[]`)**: one top-level declaration applies to the entire batch, which **holds its write scope atomically**. The normalized scope is injected into each stage's prompt as a boundary reminder.
96
+ - **Single-writer exclusion (enforced before dispatch)**: `delegate` holds a lease per subagent; `orchestrate` holds one for the entire batch. Both share a process-wide lease table and check for overlaps across tools. Any overlap raises `write-scope-conflict` **before any subagent starts**, including the conflicting path, lease holder, expiration time, and `agentsStarted: 0`, preventing Workers from overwriting the same file concurrently. Leases are released idempotently on `subagent/end`, `agent/disposed`, in `orchestrate`'s `finally` (including errors and aborts), and when the plugin is unloaded, with a 30-minute TTL as a backstop against leaks.
97
+
98
+ ---
99
+
100
+ ## Requirements
101
+
102
+ | Item | Requirement |
103
+ | --- | --- |
104
+ | **Host environment** | DeepSeek Harness Desktop / Web GUI |
105
+ | **Node.js** | `>= 22` (bundled with the DSH Desktop runtime) |
106
+ | **Plugin form** | Cordis backend service patch (`cordis.patch.yml`) + Web GUI client extension (`lib/client.js`) |
107
+ | **UI language** | Adapts to Chinese / English (`zh-CN` / `en-US`) |
108
+
109
+ ### DSH host version compatibility
110
+
111
+ The plugin depends on host subagent interfaces (the `startActivation` spec shape, the retry delivery entry point, root-agent enumeration, and the tool registry). DSH `0.2.2-rc.2` introduced a breaking change to these interfaces, so **plugin and host versions must be chosen as a pair**:
112
+
113
+ | Plugin version | Supported DSH host | Notes |
114
+ | --- | --- | --- |
115
+ | `@sshirkit/dsh-orchestrator >= 0.8.3` (current version: `0.8.4`) | **DSH `>= 0.2.2-rc.2`** | Verified against `0.2.2-rc.2` / `0.2.2-rc.3`. Since `0.2.2-rc.2`, the host has flattened the subagent spec, removed the `Symbol.for('dsh.subagent.deliverPrompt')` delivery entry point and `agents.roots()`, and added the `wait_agent` tool. It is therefore **incompatible with `0.2.2-rc.1` and earlier**. Note: although the host adds `wait_agent`, the plugin **intentionally keeps its default whitelist at 12 tools and excludes `wait_agent`**. Blocking polling can leave the main agent idling and misjudging timeouts; supervision already replaces polling with one summary plus one decision. If needed, manually check `wait_agent` in the panel's `allowedTools` list. |
116
+ | `dsh-orchestrator 0.8.0 – 0.8.2` | **DSH `<= 0.2.2-rc.1`** | Tested against `0.2.1-rc.3` and `0.2.2-rc.1`. The `@deepseek-ai/dsh-tools` dependency was introduced in `0.8.0`. |
117
+ | `dsh-orchestrator <= 0.7.3` | DSH releases predating plugin `0.8.0` | Early standalone tool-registration architecture, without a dependency on `@deepseek-ai/dsh-tools`. |
118
+
119
+ > Check the host version before upgrading: see About in DSH or read `package.json` in the installation directory. **Plugin `0.8.3+` with a `0.2.2-rc.1` or older host fails outright when dispatching**; an older plugin with a `0.2.2-rc.2+` host is also unusable. If you cannot upgrade the host yet, stay on plugin `v0.8.2`.
120
+
121
+ ---
122
+
123
+ ## Installation
124
+
125
+ Select Add from GitHub on the DSH plugin page. All three forms below are accepted; paste one into the input field. The first is recommended because it is the least likely to be misinterpreted by the client:
126
+
127
+ ```text
128
+ https://github.com/SShiRkiT/dsh-orchestrator
129
+ github:SShiRkiT/dsh-orchestrator#main
130
+ SShiRkiT/dsh-orchestrator#main
131
+ ```
132
+
133
+ ```bash
134
+ # Equivalent CLI installation
135
+ dsh plugin --profile desktop add https://github.com/SShiRkiT/dsh-orchestrator
136
+ # npm installation (available after publication to npm)
137
+ dsh plugin --profile desktop add @sshirkit/dsh-orchestrator
138
+ ```
139
+
140
+ > After installation, **fully quit and reopen DSH** (client plugins are composed at startup and do not support hot updates). When upgrading, **uninstall the old version** from the plugin page before adding this repository again or `@sshirkit/dsh-orchestrator` (available after publication to npm); two installed copies will compete over the same tool declarations.
141
+
142
+ ---
143
+
144
+ ## Configuration
145
+
146
+ All configuration fields are volatile (dynamic configuration): changes in the panel take effect immediately, without restarting DSH:
147
+
148
+ | Field | Default | Description |
149
+ | --- | --- | --- |
150
+ | `enabled` | `true` | Master switch for dispatch mode. Turning it off immediately restores all main-agent tools in the current session. |
151
+ | `workerProvider` / `workerModel` | `""` | Default subagent model route (required; dispatch fails if unconfigured and never silently inherits the main-agent model). |
152
+ | `workerReasoningEffort` | `""` | Subagent reasoning effort. Leave empty to let the selected model use its own default. |
153
+ | `allowedTools` | 12 built-in tools | Whitelist-driven: the main agent may use only the listed tools; other host, MCP, and plugin tools are automatically hidden and disabled. Check or uncheck tools under Allowed Tools on the right of the panel to allow or disable them; changes apply on the next message. |
154
+ | `superviseEnabled` | `true` | Master switch for background subagent inspection. |
155
+ | `superviseIntervalSeconds` | `600` | Inspection interval in seconds, from 10 to 86400. Changes take effect immediately while workers are running. |
156
+ | `superviseMaxNoticesPerChild` | `3` | Maximum inspection notices per subagent (0–20). `0` disables inspection; running subagents remain registered, and inspection resumes immediately when the value is raised above 0 or unlimited inspection is enabled. |
157
+ | `superviseUnlimited` | `false` | Enables unlimited inspections. Ignores the `superviseMaxNoticesPerChild` limit (including `0`) and continues inspecting at each interval until the subagent stops, delivers, or ends. Notice titles omit the denominator (`第 N 次`). |
158
+ | `superviseNotifyOnNoProgress` | `false` | Whether to notify even when the subagent log has no new activity (effectively always enabled when `superviseUnlimited` is on). |
159
+
160
+ > Note: the main agent's default model is stored in the host's `agent-default-model`, read and written directly by the same Dispatch mode panel, and applies to newly created sessions. Subagent model changes apply to the next delegation.
161
+
162
+ ## License
163
+
164
+ [MIT](LICENSE) © 2026 [SShiRkiT](https://github.com/SShiRkiT)
package/README.md CHANGED
@@ -1,3 +1,164 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
+
3
+ ##### Start from 28th October
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <div align="center">
6
+
7
+ # DSH Orchestrator
8
+
9
+ </div>
10
+
11
+
12
+ #### **强模型主脑规划 + 便宜模型统一打工 —— DeepSeek Harness 的「硬隔离调度模式」插件**
13
+
14
+ [![version](https://img.shields.io/badge/version-0.8.4-4176E6?style=flat-square)](https://github.com/SShiRkiT/dsh-orchestrator)
15
+ [![dsh-plugin](https://img.shields.io/badge/DeepSeek%20Harness-dsh--plugin-4176E6?style=flat-square)](https://github.com/deepseek-ai/deepseek-harness)
16
+ [![platform](https://img.shields.io/badge/platform-Web%20GUI%20%7C%20Desktop-5c6bc0?style=flat-square)](https://github.com/SShiRkiT/dsh-orchestrator)
17
+ [![node](https://img.shields.io/badge/node-%3E%3D22-339933?style=flat-square&logo=nodedotjs&logoColor=white)](https://nodejs.org)
18
+ [![module](https://img.shields.io/badge/module-ESM-F7DF1E?style=flat-square&logo=javascript&logoColor=black)](package.json)
19
+ [![license](https://img.shields.io/badge/license-MIT-2ea44f?style=flat-square)](LICENSE)
20
+ [![GitHub stars](https://img.shields.io/github/stars/SShiRkiT/dsh-orchestrator?style=flat-square&logo=github)](https://github.com/SShiRkiT/dsh-orchestrator/stargazers)
21
+
22
+ **简体中文** | [English](README.en.md) · [核心差异](#为什么有了原生-subagent-和-agent-team还需要这个插件) · [核心特性](#核心特性) · [安装](#安装) · [配置说明](#配置说明)
23
+
24
+ </div>
25
+
26
+ ---
27
+ <div align="center">
28
+
29
+ ### 为什么有了原生 `subagent` 和 `Agent Team`,还需要这个插件?
30
+ </div>
31
+ DSH 客户端自带了 `subagent` / `workflow`,官方也有 `@deepseek-ai/dsh-experimental-agent-team-profile`(Agent Team),但它们在实际高强度开发中仍有三个痛点——而这正是 **DSH Orchestrator** 独有的设计核心:
32
+
33
+ | 痛点场景 | 原生 `subagent` / 官方 `Agent Team` | DSH Orchestrator(本插件独有) |
34
+ | --- | --- | --- |
35
+ | **主代理总忍不住自己动手** | **靠自觉(软提示词)**:主代理 / Team Lead 手里依然握有 `read`、`edit`、`bash` 等全套工具,聊几轮就经常脱轨亲自去读文件、跑命令,瞬间撑爆主上下文 | **白名单式驱动(Whitelist-Driven Hard Gate)**:主代理默认仅放行 12 项规划与委派核心工具(`allowedTools`),其余一切宿主读写/终端工具及未来新增的 MCP/第三方插件工具一律自动隐藏并在执行层强制拦截(连 `run_code` 嵌套偷调也拦),**逼迫 Main Agent 100% 只做规划与验收,Subagent 100% 只干苦力活** |
36
+ | **便宜模型干活卡死/跑偏** | **运行期黑盒**:派出后只能干等结束或超时,或者靠 `wait_agent` 阻塞轮询 | **后台事件日志定时巡检 + 强模型动态纠偏**:后台定时器直接读取运行中 Worker 的会话事件日志(读取与汇总本身不调用模型),汇总运行时长、轮次、新增工具调用与最后输出;异常或超时时以一条轻量摘要通知唤醒主代理,由强模型判断后精准纠偏 |
37
+ | **大批量同构任务** | 原生 `workflow` 让模型手写任意 JS 脚本,容易失控且模型路由不统一 | **声明式 `orchestrate` 流水线**:`items × stages` 结构化扇出与多阶段流水线,单项失败隔离、支持 JSON Schema 强校验,全部 Worker 强制走便宜的子代理路由 |
38
+
39
+ ---
40
+ <div align="center">
41
+
42
+ ## 核心特性
43
+ </div>
44
+
45
+ ### 1. 强模型当 Main Agent,便宜模型当 Subagent(独立面板、即时生效)
46
+
47
+ 在输入框下方的**「调度模式」专属面板**中,主代理与子代理的模型路由完全解耦:
48
+ - **主代理(Main Agent)**:配置为你最强的旗舰模型(例如 `gpt-astra-6`、`claude-opus-5.5` 等),专门负责需求澄清、任务切分、途中纠偏与最终结果验收。
49
+ - **子代理(Subagent)**:配置为能力稍弱但极其便宜、高吞吐的模型(例如 `deepseek-v4.1-flash`、`gpt-luna-6` 等),**所有通过 `delegate` 和 `orchestrate` 派出的 Worker 强制共用这条便宜路由**(除非用户在当前消息里明确点名要求临时换模型)。
50
+ - **防烧钱保护**:如果未配置子代理模型,派发时会直接报错拦截
51
+
52
+ ![调度模式面板](docs/images/dispatch-panel.png)
53
+
54
+ ### 2. 主代理「规划与验收」、子代理「纯粹 Work」的白名单式硬性闸门
55
+
56
+ 不同于靠 Prompt 劝主模型“多用子代理”,本插件在 DSH 的工具声明出口(`tools.definitions`)与执行层(`tools.guard`)安装了双重守卫,且采用**白名单式驱动**:声明层实时裁剪模型可见的工具表(全局工具与 `ops_*` 等 scope 内工具一视同仁),执行层再兜底拒绝任何漏网调用;两层都按请求/按调用实时读取配置,不产生 `tools.restrict` 事件风暴,因此不会触发官方工具遮挡的抖动与 Prompt Cache 失效。
57
+ - **主代理被彻底收缴执行工具**:
58
+ <div align="center">
59
+
60
+ > ### DEFAULT_ALLOWED_TOOLS 默认只放行 12 项规划、委派与会话只读工具
61
+ >
62
+ > _`delegate`、`orchestrate`、`send_message`、`interrupt_agent`、`todo_write`、`ask_user_question`、`compress` 与 5 项只读会话日志工具。_
63
+ >
64
+ > ### 所有文件读写、搜索、终端,以及未来新增的任何 MCP / 第三方插件工具,一律自动隐藏并在执行层强制拦截
65
+ >
66
+ >_(`read` / `edit` / `write` / `apply_patch`)、(`grep` / `glob`)、(`bash` / `pwsh`)、 `subagent` / `workflow`_
67
+ >
68
+ > ### 连 run_code 嵌套偷调也拦。需要额外放行时,在面板右侧 Allowed Tools 勾选即可。
69
+ </div>
70
+
71
+ - **子代理独享完整工具链**:被派出的 Worker 不受闸门限制,在各自独立的上下文中读写文件、跑测试、看报错,完工后只把干净的结论交回主代理验收。
72
+ - **一键随时切换**:需要主代理临时亲自操作时,关掉面板上的「启用调度模式」开关即可立刻恢复主代理的全部工具,无需重开会话。
73
+
74
+ ### 3. 后台事件日志定时巡检与强模型动态纠偏
75
+
76
+ 便宜模型充当 Subagent 时,偶尔会在复杂的 shell 转义或报错上打转。插件内置了纯日志驱动的后台巡检器:
77
+ - **巡检读取本身不调用模型**:后台定时器直接读取运行中 Worker 的会话事件日志,按设定的巡检间隔(默认 600 秒)汇总它的运行时长、轮次、新增工具调用与最后输出,合并成一条通知唤醒主代理。读取与汇总环节不发起任何 LLM 请求
78
+ - 但**唤醒主代理后的判断与纠偏仍会消耗主代理的 token**:巡检的价值在于把「持续轮询」压缩成「一条摘要 + 一次决策」,而不是让整个巡检功能零消耗。
79
+ - **强模型一眼把关**:主代理收到巡检摘要后,只需极少 Token 即可做出决策:
80
+ - **A) 进展正常**:回复一行 `巡检:正常` 结束回合,让子代理继续跑;
81
+ - **B) 途中纠偏**:调用 `send_message` 直接向运行中的子代理注入修正指令(指明正确写法或跳过卡点);
82
+ - **C) 及时止损**:调用 `interrupt_agent` 中断失控的子代理(若后续再用 `send_message` 重新唤醒它,巡检会自动重新接管并重置通知计数)。
83
+
84
+ ![巡检通知与纠偏示例](docs/images/patrol-notice.png)
85
+
86
+ *巡检通知与纠偏实录:便宜的子代理卡在了 shell 引号和反斜杠转义上,巡检机制按间隔唤醒主代理后,主代理通过 `send_message` 直接给出正确写法完成纠偏。*
87
+
88
+ ### 4. 专为调度模式定制的 `delegate` 与 `orchestrate`
89
+
90
+ - **`delegate`(按需异步单派 / 并行扇出)**:
91
+ 用于派发自包含的独立任务(目标 + 允许修改的文件 + 验收命令 + 失败兜底)。同一回合多次调用即可同时启动多个 Worker 并行施工;插件会为每个子代理统一注入简体中文回复指令,并要求它在收尾时直接输出最终总结、禁止调用 `send_message` 向父代理汇报(收尾消息会自动送达主代理)。
92
+ **`writeScope`(必填,`string[]`)**:声明本次派发允许修改的文件或目录,支持精确文件(`src/index.js`)、目录(`dir/` 或 `dir/**`)与全局根(`*`)。相对路径按 `cwd` 词法归一化,Windows 下大小写不敏感判重;省略报 `write-scope-missing`,空数组 / 非法路径报 `write-scope-invalid`。
93
+ - **`orchestrate`(声明式批量流水线)**:
94
+ 用于处理「一组条目(`items`,1–64)× 固定多阶段步骤(`stages`,1–8)」的批量任务,通过 `maxConcurrency`(1–16,默认 4)控制并发。支持单阶段并行扇出与多阶段**逐条目无屏障流水线**(先做完阶段 1 的条目立刻进入阶段 2,不用傻等慢条目),支持阶段级 JSON Schema 强校验与单项失败隔离。
95
+ **`writeScope`(必填,`string[]`)**:整批共用一条顶层声明,按整批**原子持有**写作用域;归一化后的作用域会自动注入每个阶段的 Prompt 作为边界提示。
96
+ - **单写者互斥(派发前拦截)**:`delegate` 按子代理持锁、`orchestrate` 按整批持锁,两者共享同一张进程级租约表并跨工具求交。一旦作用域相交,插件会在**启动任何子代理之前**直接抛出 `write-scope-conflict`(附冲突路径、持有者与到期时间,`agentsStarted: 0`),杜绝多个 Worker 同时覆写同一文件。租约在 `subagent/end`、`agent/disposed`、`orchestrate` 的 `finally`(含异常与 abort)以及插件卸载时幂等释放,另有 30 分钟 TTL 兜底防泄漏。
97
+
98
+ ---
99
+
100
+ ## 环境要求
101
+
102
+ | 项目 | 要求 |
103
+ | --- | --- |
104
+ | **宿主环境** | DeepSeek Harness Desktop / Web GUI |
105
+ | **Node.js** | `>= 22`(内置于 DSH Desktop 运行时) |
106
+ | **插件形态** | Cordis 后端服务补丁(`cordis.patch.yml`)+ Web GUI 客户端扩展(`lib/client.js`) |
107
+ | **界面语言** | 中 / 英双语自适应(`zh-CN` / `en-US`) |
108
+
109
+ ### 与 DSH 宿主的版本兼容性
110
+
111
+ 插件依赖宿主的子代理接口(`startActivation` 的 spec 形状、重试投递入口、根代理枚举、工具注册表),这些接口在 DSH `0.2.2-rc.2` 发生过一次不兼容变更,因此**插件版本与宿主版本必须成对选择**:
112
+
113
+ | 插件版本 | 适配的 DSH 宿主 | 说明 |
114
+ | --- | --- | --- |
115
+ | `@sshirkit/dsh-orchestrator >= 0.8.3`(当前版本 `0.8.4`) | **DSH `>= 0.2.2-rc.2`** | 已验证 `0.2.2-rc.2` / `0.2.2-rc.3`。宿主自 `0.2.2-rc.2` 起扁平化了 subagent spec、移除了 `Symbol.for('dsh.subagent.deliverPrompt')` 投递入口与 `agents.roots()`,并新增 `wait_agent` 工具;因此**不兼容 `0.2.2-rc.1` 及更早版本**。注意:宿主虽新增了 `wait_agent`,但本插件默认白名单**有意维持 12 项、不予放行 `wait_agent`**——阻塞式轮询等待会让主代理陷入空转与超时误判,巡检机制已用「一条摘要 + 一次决策」替代轮询;确有需要时可在面板 `allowedTools` 中手动勾选放行。 |
116
+ | `dsh-orchestrator 0.8.0 – 0.8.2` | **DSH `<= 0.2.2-rc.1`** | 已实测支持 `0.2.1-rc.3`、`0.2.2-rc.1`。自 `0.8.0` 起引入 `@deepseek-ai/dsh-tools` 依赖。 |
117
+ | `dsh-orchestrator <= 0.7.3` | `0.8.0` 之前的旧版 DSH | 早期独立工具注册架构,未依赖 `@deepseek-ai/dsh-tools`。 |
118
+
119
+ > 升级前请先确认宿主版本:在 DSH 中查看「关于」或读取安装目录下的 `package.json`。**插件 `0.8.3+` 配 `0.2.2-rc.1` 及更早宿主会在派发时直接报错**;反之,旧插件配 `0.2.2-rc.2+` 宿主同样不可用。若暂时无法升级宿主,请停留在插件 `v0.8.2`。
120
+
121
+ ---
122
+
123
+ ## 安装
124
+
125
+ 在 DSH 插件页选择「从 GitHub 添加」,下列三种写法都接受,直接填入输入框即可(推荐第一种,最不容易被客户端误判):
126
+
127
+ ```text
128
+ https://github.com/SShiRkiT/dsh-orchestrator
129
+ github:SShiRkiT/dsh-orchestrator#main
130
+ SShiRkiT/dsh-orchestrator#main
131
+ ```
132
+
133
+ ```bash
134
+ # CLI 等价安装
135
+ dsh plugin --profile desktop add https://github.com/SShiRkiT/dsh-orchestrator
136
+ # npm 安装(npm 发布后可用)
137
+ dsh plugin --profile desktop add @sshirkit/dsh-orchestrator
138
+ ```
139
+
140
+ > 装完后请**完全退出并重新打开 DSH**(客户端插件在启动时组合,不支持热更新)。升级时请先在插件页**卸载旧版**再重新添加本仓库或 `@sshirkit/dsh-orchestrator`(npm 发布后可用),两份同时存在会争抢同一批工具声明。
141
+
142
+ ---
143
+
144
+ ## 配置说明
145
+
146
+ 所有配置项均为 volatile(动态热配置),在面板中修改后立即生效,无需重启 DSH:
147
+
148
+ | 字段 | 默认值 | 说明 |
149
+ | --- | --- | --- |
150
+ | `enabled` | `true` | 调度模式总开关。关闭时立即对当前会话恢复主代理全部工具。 |
151
+ | `workerProvider` / `workerModel` | `""` | 子代理默认模型路由(必填,未配置时派发直接报错,绝不静默继承主代理模型)。 |
152
+ | `workerReasoningEffort` | `""` | 子代理思考强度,留空则由所选模型自行决定默认值。 |
153
+ | `allowedTools` | 12 项内置白名单 | 白名单式驱动:主代理仅可使用列表内的工具,其余宿主/MCP/插件工具自动隐藏并禁用;面板右侧 Allowed Tools 可直接勾选放行或取消勾选禁用,下一条消息即刻生效。 |
154
+ | `superviseEnabled` | `true` | 子代理后台巡检总开关。 |
155
+ | `superviseIntervalSeconds` | `600` | 巡检间隔(秒),范围 10–86400,运行中修改立即生效。 |
156
+ | `superviseMaxNoticesPerChild` | `3` | 每个子代理最多发送几次巡检通知(0–20)。`0` 表示关闭巡检(运行中的子代理仍保留在注册表中,改回 >0 或打开无限巡检后立即恢复)。 |
157
+ | `superviseUnlimited` | `false` | 无限次数巡检开关。开启后忽略 `superviseMaxNoticesPerChild` 上限(含 `0`),只要子代理没有停止 / 交付 / 结束,就按间隔持续巡检,通知标题不带分母(`第 N 次`)。 |
158
+ | `superviseNotifyOnNoProgress` | `false` | 子代理日志无新活动时是否仍然发送通知(开启 `superviseUnlimited` 时等效于始终发送)。 |
159
+
160
+ > 注:主代理的默认模型保存在宿主的 `agent-default-model` 中,由同一个「调度模式」面板直接读写,对新创建的会话生效;子代理模型改动从下一次委派起立即生效。
161
+
162
+ ## License
163
+
164
+ [MIT](LICENSE) © 2026 [SShiRkiT](https://github.com/SShiRkiT)
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: orchestrator
3
+ name: "@sshirkit/dsh-orchestrator"
Binary file
Binary file
package/lib/api.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Public names, result kind and numeric limits, kept in one place so the tools,
3
+ * the gate and the tests cannot drift apart.
4
+ *
5
+ * Dependency-free on purpose: importing this file must stay cheap and safe from
6
+ * pure unit tests.
7
+ */
8
+
9
+ export const DELEGATE_TOOL = 'delegate'
10
+ export const ORCHESTRATE_TOOL = 'orchestrate'
11
+
12
+ /**
13
+ * Refusal message when a dispatch tool (`delegate` or `orchestrate`) is invoked
14
+ * while dispatch mode (`config.enabled`) is turned off.
15
+ */
16
+ export function disabledToolMessage(tool) {
17
+ return `orchestrator: "${tool}" is disabled while dispatch mode is off. Execute the task directly with your regular tools instead of delegating.`
18
+ }
19
+
20
+ /** The `kind` field of the unified orchestration result. */
21
+ export const ORCHESTRATION_KIND = 'orchestration'
22
+
23
+ /**
24
+ * Where a started child delivers its result. `delegate` answers the parent agent
25
+ * (the existing behaviour); `orchestrate` answers its caller, because the tool
26
+ * itself waits for the result.
27
+ */
28
+ export const DELIVERY = Object.freeze({
29
+ delegate: 'parent',
30
+ orchestrate: 'caller',
31
+ })
32
+
33
+ export const LIMITS = Object.freeze({
34
+ /** One item per worker at the start of the fan-out. */
35
+ items: Object.freeze({ min: 1, max: 64 }),
36
+ /** A pipeline stage is one worker call per item. */
37
+ stages: Object.freeze({ min: 1, max: 8 }),
38
+ maxConcurrency: Object.freeze({ min: 1, max: 16, default: 4 }),
39
+ /** A larger serialized result is an explicit error, never a silent truncation. */
40
+ serializedResultChars: 50000,
41
+ })
package/lib/catalog.js ADDED
@@ -0,0 +1,217 @@
1
+ /**
2
+ * The live tool catalog the Allowed Tools panel renders, and the candidate set the
3
+ * gate hides from.
4
+ *
5
+ * A web client plugin cannot enumerate the Host's tools: the session remote exposes
6
+ * session/model/skill methods only, and `configForms` exposes this plugin's own config.
7
+ * The catalog therefore travels through that config: a volatile field the Host serves
8
+ * through `settings.describe()` and every open web client mirrors. The plugin commits it
9
+ * in memory — the same reference protocol the Loader uses for a volatile write — and then
10
+ * announces `settings/document-updated`, the event the client-side settings mirror already
11
+ * refreshes on.
12
+ *
13
+ * The catalog is the whole registered tool set, not a subset: the panel needs every name
14
+ * to offer a complete Allowed Tools checklist, and the gate needs the same names to work
15
+ * out which ones the whitelist leaves out. It is read-only and recomputed from the live
16
+ * registry on every `tools/change`, so a plugin or MCP tool that registers later shows up
17
+ * without a restart.
18
+ *
19
+ * Nothing here reaches the profile file: a settings edit writes only the paths it names,
20
+ * and the panel only ever names `allowedTools`. Because the commit does not go through the
21
+ * Loader, it also never emits `loader/volatile-update`, so refreshing the catalog cannot
22
+ * reinstall every main agent's mask.
23
+ */
24
+
25
+ import { isDelegatedChild } from './gate.js'
26
+
27
+ /** The config field that carries the catalog. */
28
+ export const CATALOG_KEY = 'toolCatalog'
29
+
30
+ /** The shared reference protocol a schemastery `.volatile()` field implements. */
31
+ const VOLATILE_WRITE = Symbol.for('cosmokit.volatile.write')
32
+
33
+ /** Whether a config field is a live volatile reference this plugin may commit. */
34
+ export function isVolatileRef(value) {
35
+ if (typeof value !== 'object' || value === null) return false
36
+ return typeof value.get === 'function' && typeof value[VOLATILE_WRITE] === 'function'
37
+ }
38
+
39
+ /**
40
+ * Every name one registry view knows. `knownNames` keeps the names a restriction
41
+ * currently hides — a tool outside the whitelist must stay listable, otherwise the
42
+ * panel could never offer it again — while `visible` adds the scope's own
43
+ * registrations, which a restriction never masks.
44
+ */
45
+ export function viewNames(view) {
46
+ const names = new Set()
47
+ if (view === undefined || view === null) return []
48
+ for (const name of view.knownNames ?? []) names.add(name)
49
+ const visible = view.visible
50
+ if (visible !== undefined && visible !== null && typeof visible.keys === 'function') {
51
+ for (const name of visible.keys()) names.add(name)
52
+ }
53
+ return [...names]
54
+ }
55
+
56
+ /** Sorted, de-duplicated union of every name the given views know. */
57
+ export function catalogOf(views) {
58
+ const names = new Set()
59
+ for (const view of views ?? []) {
60
+ for (const name of viewNames(view)) {
61
+ if (typeof name === 'string' && name !== '') names.add(name)
62
+ }
63
+ }
64
+ return [...names].sort()
65
+ }
66
+
67
+ /**
68
+ * The views that matter for the panel: the context-global one (every tool a plugin
69
+ * registers at the top level, MCP tools included) plus each live root agent's, the only
70
+ * place a preset tool or a scope-local tool such as the native `subagent` is visible.
71
+ * One unreadable view never drops the others.
72
+ *
73
+ * DSH `>= 0.2.2-rc.2` replaced `agents.roots()` with `agents.list()`, which returns every
74
+ * live agent — delegated children included. A child's scope is not a main agent's surface,
75
+ * so the list is filtered with `isDelegatedChild` (the same depth test the gate uses) to
76
+ * keep exactly the roots. A registry that cannot be read at all contributes no scopes.
77
+ */
78
+ export function collectCatalog(ctx) {
79
+ const views = []
80
+ try {
81
+ if (typeof ctx?.tools?.view === 'function') views.push(ctx.tools.view())
82
+ } catch {
83
+ // An older registry without `view()` leaves only the agent scopes.
84
+ }
85
+ let roots = []
86
+ try {
87
+ const listed = ctx?.agents?.list?.() ?? []
88
+ roots = Array.isArray(listed) ? listed.filter((agent) => !isDelegatedChild(agent)) : []
89
+ } catch {
90
+ roots = []
91
+ }
92
+ for (const agent of roots) {
93
+ try {
94
+ const view = agent?.ctx?.tools?.view?.(agent)
95
+ if (view !== undefined) views.push(view)
96
+ } catch {
97
+ // A scope that is gone, or cannot be read, contributes nothing.
98
+ }
99
+ }
100
+ return catalogOf(views)
101
+ }
102
+
103
+ /** Report a failure without ever letting the report itself break the host. */
104
+ function warn(logger, message) {
105
+ try {
106
+ logger?.warn?.(message)
107
+ } catch {
108
+ // A logger must never break a refresh.
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Keep the published catalog in step with the registry.
114
+ *
115
+ * `publish` reads the live views, compares the result with what is already published,
116
+ * and — only on a real change — commits the new snapshot and announces it. `schedule`
117
+ * debounces a burst of `tools/change` events (a plugin load registers dozens of tools)
118
+ * into one read, so neither a burst nor an unchanged set produces more than one event.
119
+ * `dispose` drops a pending read, so a plugin reload leaves no timer behind.
120
+ *
121
+ * A host whose config field is not writable (an older host, a stand-in in a unit test) is
122
+ * reported once and otherwise ignored: the panel then keeps its built-in fallback.
123
+ */
124
+ export function createCatalogPublisher({ ctx, config, key = CATALOG_KEY, debounceMs = 150, collect, logger = ctx?.logger }) {
125
+ const ref = config?.[key]
126
+ const writable = isVolatileRef(ref)
127
+ const read = typeof collect === 'function' ? collect : () => collectCatalog(ctx)
128
+ let published = []
129
+ let announced = 0
130
+ let timer
131
+ let disposed = false
132
+ let warned = false
133
+
134
+ /** The settings namespace of this plugin entry: the id the profile gives the entry. */
135
+ const namespace = () => {
136
+ const id = ctx?.fiber?.entry?.id
137
+ return typeof id === 'string' && id !== '' ? id : 'orchestrator'
138
+ }
139
+
140
+ const same = (left, right) =>
141
+ left.length === right.length && left.every((name, index) => name === right[index])
142
+
143
+ /** Whether the committed reference still holds the catalog (it may have been reset). */
144
+ const refHolds = (names) => {
145
+ try {
146
+ return same(ref.get(), names)
147
+ } catch {
148
+ return false
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Read the registry and publish the catalog. A change of content is committed and
154
+ * announced; an unchanged catalog only re-commits the value when a settings write
155
+ * reset the reference (the Loader commits the profile's raw value into every volatile
156
+ * field it was handed), because the panel would otherwise fall back to its built-in
157
+ * copy after every checkbox click.
158
+ */
159
+ const publish = () => {
160
+ if (disposed) return { changed: false, names: published }
161
+ let names
162
+ try {
163
+ names = read()
164
+ } catch (error) {
165
+ warn(logger, `orchestrator: cannot read the tool catalog: ${error instanceof Error ? error.message : String(error)}`)
166
+ return { changed: false, names: published }
167
+ }
168
+ // An empty read is a failed read, not an empty registry: keep the last catalog (or
169
+ // nothing, which makes the panel fall back to its built-in copy).
170
+ if (!Array.isArray(names) || names.length === 0) return { changed: false, names: published }
171
+ const contentChanged = !same(published, names)
172
+ if (!contentChanged && (!writable || refHolds(names))) return { changed: false, names: published }
173
+ if (!writable) {
174
+ // A host whose field is a plain value cannot be served; report it once and stop.
175
+ published = names
176
+ if (!warned) {
177
+ warned = true
178
+ warn(logger, 'orchestrator: the tool catalog is not publishable: the config field is not a volatile reference')
179
+ }
180
+ return { changed: contentChanged, names: published }
181
+ }
182
+ published = names
183
+ try {
184
+ ref[VOLATILE_WRITE](names)
185
+ } catch (error) {
186
+ warn(logger, `orchestrator: cannot publish the tool catalog: ${error instanceof Error ? error.message : String(error)}`)
187
+ return { changed: false, names: published }
188
+ }
189
+ announced += 1
190
+ try {
191
+ ctx?.emit?.('settings/document-updated', namespace(), announced)
192
+ } catch (error) {
193
+ warn(logger, `orchestrator: cannot announce the tool catalog: ${error instanceof Error ? error.message : String(error)}`)
194
+ }
195
+ return { changed: contentChanged, names }
196
+ }
197
+
198
+ /** Debounce one refresh; a second call while one is pending costs nothing. */
199
+ const schedule = () => {
200
+ if (disposed || timer !== undefined) return
201
+ timer = setTimeout(() => {
202
+ timer = undefined
203
+ publish()
204
+ }, debounceMs)
205
+ if (typeof timer?.unref === 'function') timer.unref()
206
+ }
207
+
208
+ const dispose = () => {
209
+ disposed = true
210
+ if (timer !== undefined) {
211
+ clearTimeout(timer)
212
+ timer = undefined
213
+ }
214
+ }
215
+
216
+ return { publish, schedule, dispose, published: () => published, writable }
217
+ }