dsh-plugin-subagent-bridge 0.15.1 → 0.16.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/README.md +162 -217
- package/README.zh-CN.md +322 -0
- package/index.js +8 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
# dsh-plugin-subagent-bridge
|
|
2
2
|
|
|
3
|
+
> Let Codex or Claude Code drive DeepSeek Harness sessions as subagents — and let DSH drive them back.
|
|
4
|
+
|
|
3
5
|
[](LICENSE)
|
|
4
6
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
5
7
|
<!-- M8ven ownership proof — keep this line in place; it verifies the publisher. -->
|
|
6
8
|
[](https://m8ven.ai/mcp/dogtiti-dsh-plugin-subagent-bridge-8a3t8k?s=readme)
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
两个方向共用同一个插件,各自遵守对方产品的 `maxDepth: 1`:**能派活,不能再派回来**。
|
|
10
|
+
[中文说明](README.zh-CN.md)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
The plugin runs inside the Harness host and exposes a loopback MCP endpoint. It uses public host services (`sessionController`, `sessions`, `workspaceRegistry`, `userQuestions`) — no credential files, no cookie forgery.
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Highlights
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
- **One tool call, one answer.** `dsh_task` opens a session, delivers the message, blocks until the turn ends, and returns only the final assistant text.
|
|
17
|
+
- **Parallel workers.** `dsh_spawn` returns immediately; `dsh_wait` blocks until any of them settles.
|
|
18
|
+
- **Per-call model and project.** Pin a worker to `provider/model` and file it under a named workspace without touching profile defaults.
|
|
19
|
+
- **Queue or steer.** Choose whether a follow-up waits for the running turn or is inserted into it.
|
|
20
|
+
- **Unattended by default.** Workers are told to assume a reasonable default instead of stopping to ask.
|
|
21
|
+
- **Reverse direction.** `codex_dispatch` and `claude_dispatch` hand work to Codex or Claude Code, with resumable threads.
|
|
22
|
+
- **Loop guard.** Depth and rate limits stop the two agents from delegating to each other in circles.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## Requirements
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
- DeepSeek Harness `^0.2.1-0`.
|
|
27
|
+
- Codex CLI (`codex`) and/or Claude Code CLI (`claude`) on `PATH` for the reverse direction.
|
|
27
28
|
|
|
28
|
-
##
|
|
29
|
+
## Install
|
|
29
30
|
|
|
30
31
|
```bash
|
|
31
32
|
git clone https://github.com/Dogtiti/dsh-plugin-subagent-bridge
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
Plugins →
|
|
35
|
-
|
|
36
|
-
启动后在 `127.0.0.1:47821` 监听,并把端点写到 `~/.dsh/bridge/endpoint.json`(目录 0700、文件 0600):
|
|
35
|
+
Open **Plugins → Add** in DSH and pick that directory. On start the plugin listens on `127.0.0.1:47821` and writes the endpoint file:
|
|
37
36
|
|
|
38
37
|
```json
|
|
39
38
|
{
|
|
@@ -45,184 +44,169 @@ Plugins → 添加 → 选该目录。
|
|
|
45
44
|
}
|
|
46
45
|
```
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
`~/.dsh/bridge/endpoint.json`, directory `0700`, file `0600`.
|
|
48
|
+
|
|
49
|
+
## Connect
|
|
50
|
+
|
|
51
|
+
### Codex
|
|
49
52
|
|
|
50
53
|
```bash
|
|
51
54
|
codex mcp add dsh-bridge --url "$(node -p "require(process.env.HOME+'/.dsh/bridge/endpoint.json').url")"
|
|
52
|
-
codex mcp list
|
|
53
|
-
codex mcp remove dsh-bridge #
|
|
55
|
+
codex mcp list # verify
|
|
56
|
+
codex mcp remove dsh-bridge # remove
|
|
54
57
|
```
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
The desktop app and the CLI share `~/.codex/config.toml`, so both see it. The token lives in the URL path, so no environment variable is needed — the desktop app cannot receive custom ones when launched from Finder. `Authorization: Bearer <token>` works too.
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Claude Code 同理:
|
|
61
|
+
### Claude Code
|
|
61
62
|
|
|
62
63
|
```bash
|
|
63
|
-
claude mcp add --transport http dsh-bridge "
|
|
64
|
+
claude mcp add --transport http dsh-bridge "<the url above>" --scope user
|
|
64
65
|
```
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
## 正向:Codex → DSH
|
|
69
|
-
|
|
70
|
-
### 工具
|
|
71
|
-
|
|
72
|
-
| 工具 | 作用 |
|
|
73
|
-
| --- | --- |
|
|
74
|
-
| `dsh_task` | **同步**派活:开会话、投递、阻塞到这一轮结束,只返回**最终回答** |
|
|
75
|
-
| `dsh_spawn` | **异步**派活:立刻返回 `task_name` + `sessionId`,可并行开多个 |
|
|
76
|
-
| `dsh_followup` | 给已有 worker 再派一轮(复用上下文) |
|
|
77
|
-
| `dsh_wait` | 一次等多批 worker,任一到达终态即返回 |
|
|
78
|
-
| `dsh_close` | 关闭 worker,释放并发名额(不删除会话) |
|
|
79
|
-
| `dsh_answer` | 代用户回答 worker 提出的问题(见「问题上报」) |
|
|
80
|
-
| `dsh_list_workers` | 列出本桥开的 worker 及实时状态 |
|
|
81
|
-
| `dsh_dispatch` | 向指定会话投递一条用户消息并开始一轮;返回 `requestId` 与 `seqAtDispatch` |
|
|
82
|
-
| `dsh_read_result` | **长轮询**读该会话在 `seqAtDispatch` 之后的全部助手文本(看过程用;要结果用 `dsh_wait`) |
|
|
83
|
-
| `dsh_list_sessions` | 列出会话**元数据**(id、标题、工作目录、是否运行、最后活动时间) |
|
|
84
|
-
|
|
85
|
-
### 基本用法
|
|
67
|
+
## Usage
|
|
86
68
|
|
|
87
69
|
```js
|
|
88
|
-
//
|
|
89
|
-
dsh_task({ prompt: "
|
|
70
|
+
// Synchronous: wait for the turn, get the answer
|
|
71
|
+
dsh_task({ prompt: "Review the error handling in src/bridge.ts", cwd: "/repo" })
|
|
90
72
|
|
|
91
|
-
//
|
|
73
|
+
// Asynchronous: hand out work, then wait for all of it
|
|
92
74
|
dsh_spawn({ task_name: "audit_api", message: "…", cwd: "/repo" })
|
|
93
75
|
dsh_spawn({ task_name: "audit_ui", message: "…", cwd: "/repo" })
|
|
94
76
|
dsh_wait({ targets: ["audit_api", "audit_ui"], timeoutMs: 240000 })
|
|
95
77
|
|
|
96
|
-
//
|
|
97
|
-
dsh_followup({ worker: "audit_api", message: "
|
|
78
|
+
// Continue an existing worker
|
|
79
|
+
dsh_followup({ worker: "audit_api", message: "Expand item 3 and attach a patch" })
|
|
98
80
|
```
|
|
99
81
|
|
|
100
|
-
|
|
82
|
+
## Tools
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
| Tool | Purpose |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `dsh_task` | Synchronous dispatch: create session, deliver, block to end of turn, return the final answer |
|
|
87
|
+
| `dsh_spawn` | Asynchronous dispatch: returns `task_name` + `sessionId` immediately |
|
|
88
|
+
| `dsh_followup` | Another round on an existing worker, reusing its context |
|
|
89
|
+
| `dsh_wait` | Wait on several workers at once; returns when any reaches a terminal state |
|
|
90
|
+
| `dsh_close` | Close a worker and free its slot (the session stays) |
|
|
91
|
+
| `dsh_answer` | Answer a worker's question (limited — see below) |
|
|
92
|
+
| `dsh_list_workers` | List workers started by this bridge and their live status |
|
|
93
|
+
| `dsh_dispatch` | Deliver one message to any session; returns `requestId` and `seqAtDispatch` |
|
|
94
|
+
| `dsh_read_result` | Long-poll the assistant text produced after `seqAtDispatch` |
|
|
95
|
+
| `dsh_list_sessions` | List session metadata only (id, title, cwd, running, last activity) |
|
|
104
96
|
|
|
105
|
-
|
|
97
|
+
`dsh_list_sessions` never returns message content, and `dsh_read_result` only works for sessions this bridge has dispatched to.
|
|
106
98
|
|
|
107
|
-
|
|
99
|
+
### Model
|
|
108
100
|
|
|
109
101
|
```js
|
|
110
102
|
dsh_task({ prompt: "…", model: "zai-coding-cn/glm-5.3", reasoningEffort: "max" })
|
|
111
103
|
dsh_spawn({ task_name: "review", message: "…", model: "opencode-go/deepseek-v4.1-flash" })
|
|
112
104
|
```
|
|
113
105
|
|
|
114
|
-
-
|
|
115
|
-
- `reasoningEffort`
|
|
116
|
-
-
|
|
117
|
-
-
|
|
106
|
+
- `provider/model`; a bare model id keeps the current default provider.
|
|
107
|
+
- `reasoningEffort` is optional and model-dependent.
|
|
108
|
+
- Omitted means the session is untouched.
|
|
109
|
+
- The switch happens before the first prompt, so the worker's first turn already runs on it, and the profile default model is not modified.
|
|
118
110
|
|
|
119
|
-
|
|
111
|
+
### Workspace
|
|
120
112
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
DSH 的侧边栏分组(项目 / workspace)和工作目录是两回事:新建会话默认落在「未分组」,除非所在目录已经是项目。
|
|
113
|
+
DSH groups sessions into projects; a new session lands under "Ungrouped" unless its directory is already a project.
|
|
124
114
|
|
|
125
115
|
```js
|
|
126
|
-
dsh_task({ prompt: "…", cwd: "/repo/clawer", workspace: true })
|
|
116
|
+
dsh_task({ prompt: "…", cwd: "/repo/clawer", workspace: true }) // create, titled after the directory
|
|
127
117
|
dsh_spawn({ task_name: "w1", message: "…", cwd: "/repo/clawer", workspace: "Clawer" })
|
|
128
|
-
dsh_task({ prompt: "…", cwd: "/repo/clawer" })
|
|
118
|
+
dsh_task({ prompt: "…", cwd: "/repo/clawer" }) // reuse only
|
|
129
119
|
```
|
|
130
120
|
|
|
131
|
-
|
|
132
|
-
- 目录已经是项目 → **复用,不改标题**;
|
|
133
|
-
- 返回里带 `workspace: { id, title, path }`;
|
|
134
|
-
- 项目操作失败不影响派发本身。
|
|
121
|
+
Missing directories are created first (registration requires an existing directory). An existing project is reused without retitling. The result carries `workspace: { id, title, path }`. A failure here never fails the dispatch.
|
|
135
122
|
|
|
136
|
-
###
|
|
123
|
+
### Queue or steer
|
|
137
124
|
|
|
138
|
-
DSH
|
|
125
|
+
DSH's "sending while busy" has exactly two behaviours:
|
|
139
126
|
|
|
140
|
-
| `mode` |
|
|
141
|
-
| --- | --- |
|
|
142
|
-
| `queue
|
|
143
|
-
| `steer` |
|
|
127
|
+
| `mode` | Behaviour |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `queue` (default) | Wait for the current turn, then deliver as a new turn |
|
|
130
|
+
| `steer` | Insert into the current turn; the model sees it at the next step |
|
|
144
131
|
|
|
145
132
|
```js
|
|
146
|
-
dsh_followup({ worker: "w1", message: "
|
|
133
|
+
dsh_followup({ worker: "w1", message: "Only touch files under src from here", mode: "steer" })
|
|
147
134
|
```
|
|
148
135
|
|
|
149
|
-
|
|
136
|
+
Two measured facts:
|
|
150
137
|
|
|
151
|
-
1. **`steer`
|
|
152
|
-
2. **`steer`
|
|
138
|
+
1. **`steer` does not interrupt a running tool call.** A worker inside `sleep 90` only sees the message when that call returns (70s in our test). Stopping it is the UI's cancel action, not a delivery mode.
|
|
139
|
+
2. **`steer` does not open a new turn** — the turn number stays the same, so the bridge waits for the *current* turn to end. Waiting for the next one blocks until the timeout.
|
|
153
140
|
|
|
154
|
-
`dsh_task`
|
|
141
|
+
`dsh_task` refuses a running session unless `mode: "steer"` is given, and the error message says so. A steered reply shares the turn with the original task, so the bridge anchors the answer on its own user message rather than the turn's last assistant text.
|
|
155
142
|
|
|
156
|
-
###
|
|
143
|
+
### Unattended workers
|
|
157
144
|
|
|
158
|
-
worker
|
|
145
|
+
A worker that calls `ask_user_question` waits for a human. When the caller is another agent, nobody is there. So the bridge appends a standing instruction to every delegated task:
|
|
159
146
|
|
|
160
147
|
```
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
(If information is missing, or a choice between options is required, pick the most
|
|
149
|
+
reasonable default, finish the task, and state the assumption in one line. Do not
|
|
150
|
+
hand the decision back to the user and do not call ask_user_question.)
|
|
164
151
|
```
|
|
165
152
|
|
|
166
|
-
|
|
167
|
-
- `dsh_task`、`dsh_spawn`、`dsh_followup` 三条路径都会加;
|
|
168
|
-
- prompt 里本来就提到 `ask_user_question` 时不追加。
|
|
153
|
+
Set your own wording with `assumptionPolicy`:
|
|
169
154
|
|
|
170
|
-
|
|
155
|
+
```yaml
|
|
156
|
+
config:
|
|
157
|
+
assumptionPolicy: "If information is missing, pick the most reasonable default, finish the task, and state the assumption in one line. Do not ask the user and do not call ask_user_question."
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
On by default (`assumeDefaults: false` disables it). It is skipped when the prompt already mentions `ask_user_question`.
|
|
171
161
|
|
|
172
|
-
|
|
162
|
+
> The built-in default text is Chinese (`如果缺少必要信息……`), which every model in this host reads; the block above is that instruction in English. Set `assumptionPolicy` to send English verbatim.
|
|
173
163
|
|
|
174
|
-
|
|
164
|
+
### Questions (`pendingQuestion`)
|
|
165
|
+
|
|
166
|
+
If a worker does ask, `dsh_wait` reports it:
|
|
175
167
|
|
|
176
168
|
```jsonc
|
|
177
169
|
{
|
|
178
170
|
"status": { "w1": "running" },
|
|
179
|
-
"timedOut": true,
|
|
180
171
|
"pendingQuestion": {
|
|
181
172
|
"callId": "call_abc",
|
|
182
|
-
"questions": [{
|
|
183
|
-
"id": "mode",
|
|
184
|
-
"question": "用哪种模式?",
|
|
185
|
-
"header": "Choose Mode",
|
|
186
|
-
"options": [{ "label": "快速", "description": "只跑单测" }, { "label": "完整" }]
|
|
187
|
-
}]
|
|
173
|
+
"questions": [{ "id": "mode", "question": "Which mode?", "options": [{ "label": "Fast" }] }]
|
|
188
174
|
},
|
|
189
175
|
"next": "blocked on a question: answer it with dsh_answer, or call dsh_wait again"
|
|
190
176
|
}
|
|
191
177
|
```
|
|
192
178
|
|
|
193
|
-
`dsh_answer({ worker, answers: [{ id, selected: [
|
|
179
|
+
`dsh_answer({ worker, answers: [{ id: "mode", selected: ["Fast"] }] })` submits a batch.
|
|
194
180
|
|
|
195
|
-
|
|
181
|
+
**Known limit:** DSH's `userQuestions.answer()` only accepts questions that have already timed out into the `continued` state. A question still blocking inside the tool call belongs to the web UI's answerer, and the bridge cannot answer it (`answered: false` in practice). Prefer `assumeDefaults` over waiting for a question.
|
|
196
182
|
|
|
197
|
-
##
|
|
183
|
+
## Reverse direction
|
|
198
184
|
|
|
199
|
-
|
|
185
|
+
Both tools are registered for agents of this deployment.
|
|
200
186
|
|
|
201
187
|
### `codex_dispatch`
|
|
202
188
|
|
|
203
|
-
|
|
|
189
|
+
| Parameter | Description |
|
|
204
190
|
| --- | --- |
|
|
205
|
-
| `prompt` |
|
|
206
|
-
| `cwd` |
|
|
207
|
-
| `resume` | Codex
|
|
191
|
+
| `prompt` | Required task text |
|
|
192
|
+
| `cwd` | Working directory; defaults to the calling session's |
|
|
193
|
+
| `resume` | Codex thread id to continue |
|
|
208
194
|
| `sandbox` | `read-only` / `workspace-write` / `danger-full-access` |
|
|
209
195
|
|
|
210
|
-
|
|
196
|
+
Returns `{ ok, text, threadId, exitCode, durationMs }`. Runs `codex exec [resume <id>] --json -o <tmpfile>`, reads `thread.started` from the event stream and the final message from the `-o` file. **`sandbox` and `cwd` are ignored on `resume`** — `codex exec resume` accepts neither.
|
|
211
197
|
|
|
212
198
|
### `claude_dispatch`
|
|
213
199
|
|
|
214
|
-
|
|
|
200
|
+
| Parameter | Description |
|
|
215
201
|
| --- | --- |
|
|
216
|
-
| `prompt` |
|
|
217
|
-
| `cwd` |
|
|
218
|
-
| `resume` | Claude Code
|
|
219
|
-
| `model` |
|
|
220
|
-
|
|
221
|
-
返回 `{ ok, text, sessionId, durationMs }`。执行 `claude -p --output-format json`,只读 stdout 的单个 JSON 对象;**stderr 的警告不算失败**(模型名带 `[1M]` 后缀时 CLI 会警告,但结果正常)。
|
|
202
|
+
| `prompt` | Required task text |
|
|
203
|
+
| `cwd` | Working directory |
|
|
204
|
+
| `resume` | Claude Code session id |
|
|
205
|
+
| `model` | Model alias or id; falls back to config, then to the CLI's own setting |
|
|
222
206
|
|
|
223
|
-
|
|
207
|
+
Returns `{ ok, text, sessionId, durationMs }`. Runs `claude -p --output-format json` and reads the single JSON object on stdout. **stderr is advisory** — the CLI warns about an unrecognised model suffix while still succeeding.
|
|
224
208
|
|
|
225
|
-
##
|
|
209
|
+
## Configuration
|
|
226
210
|
|
|
227
211
|
```yaml
|
|
228
212
|
- insert:
|
|
@@ -232,148 +216,109 @@ worker 真的问了问题时,`dsh_wait` 会把问题原样带出来:
|
|
|
232
216
|
port: 47821
|
|
233
217
|
```
|
|
234
218
|
|
|
235
|
-
|
|
|
219
|
+
| Key | Default | Description |
|
|
236
220
|
| --- | --- | --- |
|
|
237
|
-
| `enabled` | `true` |
|
|
238
|
-
| `port` | `47821` |
|
|
239
|
-
| `endpointFile` | `~/.dsh/bridge/endpoint.json` |
|
|
240
|
-
| `maxResultChars` | `20000` |
|
|
241
|
-
| `taskTimeoutSeconds` | `300` | `dsh_task`
|
|
242
|
-
| `assumeDefaults` | `true` |
|
|
243
|
-
| `
|
|
244
|
-
| `
|
|
245
|
-
| `
|
|
246
|
-
| `
|
|
247
|
-
| `
|
|
248
|
-
| `
|
|
249
|
-
| `
|
|
250
|
-
| `
|
|
251
|
-
| `
|
|
252
|
-
| `
|
|
253
|
-
| `
|
|
254
|
-
| `
|
|
255
|
-
| `
|
|
256
|
-
| `
|
|
257
|
-
| `
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
### 防环
|
|
266
|
-
|
|
267
|
-
两个 agent 都接了同一个桥时存在真实环路:DSH worker → `codex_dispatch` → 那次 Codex 也能看到 `dsh-bridge` → 又 `dsh_spawn` → …。双方进程内的深度规则都管不到这条链(桥建的 worker 是顶层会话,深度恒为 0)。
|
|
268
|
-
|
|
269
|
-
**① 深度(`maxHops`,默认 1)**:每次派发都计算 `max(在飞链路深度, 调用方深度) + 1`,超限直接报错:
|
|
221
|
+
| `enabled` | `true` | Master switch; when off, no listener and no endpoint file |
|
|
222
|
+
| `port` | `47821` | Loopback port; fixed so the client URL survives restarts |
|
|
223
|
+
| `endpointFile` | `~/.dsh/bridge/endpoint.json` | Where the endpoint and token are written |
|
|
224
|
+
| `maxResultChars` | `20000` | Cap on a single result payload (the head is kept) |
|
|
225
|
+
| `taskTimeoutSeconds` | `300` | `dsh_task` wait cap (client may override, max 240) |
|
|
226
|
+
| `assumeDefaults` | `true` | Append the decide-and-continue instruction |
|
|
227
|
+
| `assumptionPolicy` | *(empty)* | Replacement text for the instruction; empty uses the built-in Chinese default |
|
|
228
|
+
| `workersFile` | `~/.dsh/bridge/workers.json` | Worker registry (`0600`) |
|
|
229
|
+
| `maxHops` | `1` | Delegation depth limit |
|
|
230
|
+
| `dispatchPerMinute` | `10` | Dispatches allowed per window |
|
|
231
|
+
| `dispatchWindowMs` | `60000` | Window length |
|
|
232
|
+
| `maxWorkersPerRoot` | `4` | Workers per working directory |
|
|
233
|
+
| `maxWorkers` | `12` | Global worker cap |
|
|
234
|
+
| `workerTtlMs` | `86400000` | Records stop counting once stale |
|
|
235
|
+
| `waitTimeoutMs` | `240000` | Default `dsh_wait` timeout |
|
|
236
|
+
| `readWaitSeconds` | `25` | Default `dsh_read_result` long-poll |
|
|
237
|
+
| `codexBin` | `codex` | Codex executable; a value with `/` is resolved strictly |
|
|
238
|
+
| `codexSandbox` | `workspace-write` | Default sandbox for `codex_dispatch` |
|
|
239
|
+
| `codexTimeoutMs` | `300000` | Per-run timeout |
|
|
240
|
+
| `claudeBin` | `claude` | Claude Code executable |
|
|
241
|
+
| `claudeModel` | *(empty)* | Empty means the CLI's own setting |
|
|
242
|
+
| `claudeTimeoutMs` | `300000` | Per-run timeout |
|
|
243
|
+
|
|
244
|
+
A busy port is reported, not silently replaced: the endpoint file gets an `error` field and the host log prints `subagent-bridge: could not start on port …`.
|
|
245
|
+
|
|
246
|
+
## Guardrails
|
|
247
|
+
|
|
248
|
+
**Depth.** Both agents can see the same bridge, so a circle is possible: DSH worker → `codex_dispatch` → that Codex run → `dsh_spawn` → … Each dispatch computes `max(in-flight depth, caller depth) + 1` and refuses beyond `maxHops`:
|
|
270
249
|
|
|
271
250
|
```
|
|
272
251
|
codex_dispatch would create delegation depth 2, but maxHops is 1.
|
|
273
252
|
Carry the work out directly instead of delegating again.
|
|
274
253
|
```
|
|
275
254
|
|
|
276
|
-
|
|
255
|
+
**Rate.** `dispatchPerMinute` (default 10) catches bursts and tight retry loops:
|
|
277
256
|
|
|
278
257
|
```
|
|
279
258
|
rate limit: 10 dispatches per 60s reached; retry in 23s
|
|
280
259
|
```
|
|
281
260
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
- 每个 `cwd` 默认 **4 个**(`maxWorkersPerRoot`),全局 **12 个**(`maxWorkers`);
|
|
285
|
-
- **完成但没 `dsh_close` 的仍占名额**;
|
|
286
|
-
- 记录 **24 小时**没更新自动释放;
|
|
287
|
-
- 阻塞式 `dsh_task` 不计入名额,只登记。
|
|
288
|
-
|
|
289
|
-
按 `cwd` 分桶而不是按会话,是因为 MCP 端点共享、请求里没有会话身份;`cwd` 是唯一由调用方稳定提供、且语义上对应「一个项目」的维度。
|
|
290
|
-
|
|
291
|
-
### 跨重启
|
|
292
|
-
|
|
293
|
-
worker 注册表和每轮的时间基线落在 `~/.dsh/bridge/workers.json`:
|
|
261
|
+
**Slots.** 4 workers per `cwd`, 12 globally. A finished worker keeps its slot until `dsh_close`; records older than 24h stop counting. Blocking `dsh_task` calls are registered but do not consume a slot. Buckets are keyed by `cwd` because the MCP endpoint is shared and carries no session identity.
|
|
294
262
|
|
|
295
|
-
|
|
296
|
-
- 已结束的 worker,`dsh_wait` 直接返回缓存里的最终回答;
|
|
297
|
-
- 重启时还在跑的,会话未打开时状态为 `offline`;
|
|
298
|
-
- `dsh_followup` 会开新一轮并清掉旧回答;
|
|
299
|
-
- 最多保留 200 条,超出先淘汰最旧的已关闭 worker。
|
|
263
|
+
**Persistence.** `workers.json` keeps the registry and each turn's baseline: workers survive a restart, finished ones replay their cached answer, cold sessions report `offline`, and the file keeps at most 200 records.
|
|
300
264
|
|
|
301
|
-
|
|
265
|
+
**Security.** Loopback only; every request needs the token in the path or a bearer header, compared in constant time; the token is generated once and persisted. Holding the endpoint file is equivalent to being able to send messages to sessions — keep its `0600`/`0700` permissions. DSH's own sandbox and approval rules still apply to anything delivered.
|
|
302
266
|
|
|
303
|
-
|
|
304
|
-
- 请求必须带令牌:路径 `/mcp/<token>` 或 `Authorization: Bearer <token>`,定长时间比较;
|
|
305
|
-
- 令牌首次启动生成并持久化,能力 URL 稳定;
|
|
306
|
-
- 能力等价于「向指定会话投递消息」:能读到端点文件的进程就能派活,文件 0600、目录 0700;
|
|
307
|
-
- DSH 侧的权限策略不受影响,派进去的消息仍按会话自身的 sandbox / 审批策略执行。
|
|
308
|
-
|
|
309
|
-
---
|
|
310
|
-
|
|
311
|
-
## 实现
|
|
267
|
+
## How it works
|
|
312
268
|
|
|
313
269
|
```
|
|
314
|
-
Codex /
|
|
315
|
-
│ POST /mcp/<token> JSON-RPC
|
|
270
|
+
Codex / any MCP client
|
|
271
|
+
│ POST /mcp/<token> JSON-RPC (stateless, single JSON response)
|
|
316
272
|
▼
|
|
317
|
-
dsh-plugin-subagent-bridge
|
|
318
|
-
· node:http
|
|
273
|
+
dsh-plugin-subagent-bridge (inside the host process)
|
|
274
|
+
· node:http on 127.0.0.1:47821
|
|
319
275
|
· initialize / tools/list / tools/call / ping
|
|
320
276
|
· sessionController.prompt({ sessionId, requestId, mode, content })
|
|
321
|
-
· sessions.get(id).snapshotEvents()
|
|
277
|
+
· sessions.get(id).snapshotEvents() to read text back
|
|
322
278
|
```
|
|
323
279
|
|
|
324
|
-
|
|
280
|
+
The protocol is a stateless subset of streamable HTTP: each POST returns one `application/json` body and nothing is pushed, so results are collected by long polling. The server stops waiting the moment the client disconnects.
|
|
325
281
|
|
|
326
|
-
|
|
282
|
+
## Skills
|
|
327
283
|
|
|
328
|
-
|
|
284
|
+
Two installable skills turn this into behaviour a model follows rather than a tool it might forget:
|
|
329
285
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
| Skill | 装给谁 | 作用 |
|
|
286
|
+
| Skill | Install to | Purpose |
|
|
333
287
|
| --- | --- | --- |
|
|
334
|
-
| `deepseek-worker` | Codex |
|
|
335
|
-
| `delegate-to-external-agent` | DSH |
|
|
288
|
+
| `deepseek-worker` | Codex | When and how Codex should delegate to DSH |
|
|
289
|
+
| `delegate-to-external-agent` | DSH | When DSH should delegate to Codex or Claude Code |
|
|
336
290
|
|
|
337
291
|
```bash
|
|
338
|
-
# Codex 侧
|
|
339
292
|
mkdir -p ~/.codex/skills && cp -R skills/deepseek-worker ~/.codex/skills/
|
|
340
|
-
|
|
341
|
-
# DSH 侧
|
|
342
|
-
mkdir -p ~/.dsh/skills && cp -R skills/delegate-to-external-agent ~/.dsh/skills/
|
|
293
|
+
mkdir -p ~/.dsh/skills && cp -R skills/delegate-to-external-agent ~/.dsh/skills/
|
|
343
294
|
```
|
|
344
295
|
|
|
345
|
-
|
|
296
|
+
Both are plain `SKILL.md` files: YAML frontmatter (`name` + `description`) plus body. Triggering depends entirely on the description, so they carry bilingual trigger phrases and explicit "don't use" boundaries. Changes take effect without a restart.
|
|
346
297
|
|
|
347
|
-
|
|
298
|
+
## Compatibility
|
|
348
299
|
|
|
349
|
-
|
|
300
|
+
- DSH `^0.2.1-0` (`engines.dsh`).
|
|
301
|
+
- MCP protocol versions `2025-06-18`, `2025-03-26`, `2024-11-05`; unknown versions fall back to the newest.
|
|
302
|
+
- Requires the public services `sessionController`, `sessions`, `workspaceRegistry`, `userQuestions`. Missing ones surface as explicit tool errors.
|
|
350
303
|
|
|
351
|
-
|
|
352
|
-
- MCP 协议版本:`2025-06-18`、`2025-03-26`、`2024-11-05`(按客户端请求回显,未知版本回落到最新);
|
|
353
|
-
- 依赖宿主公开服务 `sessionController`、`sessions`、`workspaceRegistry`、`userQuestions`;不可用时工具返回明确错误。
|
|
354
|
-
|
|
355
|
-
## 开发
|
|
304
|
+
## Development
|
|
356
305
|
|
|
357
306
|
```bash
|
|
358
307
|
node --test "test/*.test.mjs"
|
|
359
308
|
```
|
|
360
309
|
|
|
361
|
-
83
|
|
362
|
-
|
|
363
|
-
`test/persistence.test.mjs` 单独覆盖持久化:文件权限、缺失/损坏记录、并发写、冷会话缓存与 `offline`。
|
|
364
|
-
|
|
365
|
-
---
|
|
310
|
+
83 tests: handshake and version negotiation, tool list and argument validation, dispatch call shape, result baselines, long polling, real HTTP round trips (404/405/202 and bearer), `codex exec` event parsing, binary resolution, success/failure/timeout runs, resume argument split, final-answer-only behaviour, `dsh_wait` terminal states, slot limits and release, followup rebaselining, registry persistence and restart recovery, `maxHops` and rate limiting, per-`cwd` budgets, workspace creation and reuse, `queue`/`steer` delivery and waiting, anchors for steered answers, Claude output parsing and resume arguments, `assumeDefaults` injection, `pendingQuestion` and `dsh_answer`.
|
|
366
311
|
|
|
367
|
-
##
|
|
312
|
+
## Related
|
|
368
313
|
|
|
369
|
-
|
|
|
314
|
+
| Plugin | Description |
|
|
370
315
|
| --- | --- |
|
|
371
|
-
| **dsh-plugin-subagent-bridge
|
|
372
|
-
| [dsh-plugin-composer-predict](https://github.com/Dogtiti/dsh-plugin-composer-predict) |
|
|
373
|
-
| [dsh-plugin-composer-history](https://github.com/Dogtiti/dsh-plugin-composer-history) |
|
|
374
|
-
| [dsh-plugin-usage-panel](https://github.com/Dogtiti/dsh-plugin-usage-panel) |
|
|
375
|
-
| [dsh-plugin-provider-icons](https://github.com/Dogtiti/dsh-plugin-provider-icons) |
|
|
316
|
+
| **dsh-plugin-subagent-bridge** (this repo) | Let Codex drive DSH as a subagent, and DSH drive Codex / Claude Code |
|
|
317
|
+
| [dsh-plugin-composer-predict](https://github.com/Dogtiti/dsh-plugin-composer-predict) | Predicts the next instruction as placeholder text; `Tab` accepts |
|
|
318
|
+
| [dsh-plugin-composer-history](https://github.com/Dogtiti/dsh-plugin-composer-history) | `↑` / `↓` in the composer to recall previous messages |
|
|
319
|
+
| [dsh-plugin-usage-panel](https://github.com/Dogtiti/dsh-plugin-usage-panel) | Provider quota next to the model picker |
|
|
320
|
+
| [dsh-plugin-provider-icons](https://github.com/Dogtiti/dsh-plugin-provider-icons) | Provider logos next to model names |
|
|
376
321
|
|
|
377
|
-
##
|
|
322
|
+
## License
|
|
378
323
|
|
|
379
324
|
MIT © [Dogtiti](https://github.com/Dogtiti)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# dsh-plugin-subagent-bridge
|
|
2
|
+
|
|
3
|
+
> 让 Codex 或 Claude Code 把 DeepSeek Harness 会话当作 subagent 来用 —— 反过来,DSH 也能把任务派给它们。
|
|
4
|
+
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
7
|
+
<!-- M8ven ownership proof — keep this line in place; it verifies the publisher. -->
|
|
8
|
+
[](https://m8ven.ai/mcp/dogtiti-dsh-plugin-subagent-bridge-8a3t8k?s=readme)
|
|
9
|
+
|
|
10
|
+
[English](README.md)
|
|
11
|
+
|
|
12
|
+
插件运行在 Harness 宿主进程内,对外暴露一个回环 MCP 端点。它只用宿主公开服务(`sessionController`、`sessions`、`workspaceRegistry`、`userQuestions`)——不读凭据文件,也不伪造 cookie。
|
|
13
|
+
|
|
14
|
+
## 特性
|
|
15
|
+
|
|
16
|
+
- **一次调用,一个答案。** `dsh_task` 开会话、投递消息、阻塞到这一轮结束,只返回最终的助手文本。
|
|
17
|
+
- **并行 worker。** `dsh_spawn` 立即返回;`dsh_wait` 阻塞到其中任意一个到达终态。
|
|
18
|
+
- **按次指定模型与项目。** 把 worker 钉在 `provider/model` 上、归入指定项目,且不改动 profile 默认值。
|
|
19
|
+
- **排队或插话。** 由调用方决定后续消息是等当前回合,还是插进当前回合。
|
|
20
|
+
- **默认无人值守。** worker 被告知采用合理默认继续,而不是停下来提问。
|
|
21
|
+
- **反向能力。** `codex_dispatch` 与 `claude_dispatch` 把任务交给 Codex 或 Claude Code,且线程可续接。
|
|
22
|
+
- **防环。** 深度与速率限制阻止两个 agent 互相派活绕圈。
|
|
23
|
+
|
|
24
|
+
## 环境要求
|
|
25
|
+
|
|
26
|
+
- DeepSeek Harness `^0.2.1-0`。
|
|
27
|
+
- 反向方向需要 `PATH` 上有 Codex CLI(`codex`)和/或 Claude Code CLI(`claude`)。
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/Dogtiti/dsh-plugin-subagent-bridge
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
在 DSH 里打开 **Plugins → 添加**,选择该目录。启动后插件监听 `127.0.0.1:47821`,并写入端点文件:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"url": "http://127.0.0.1:47821/mcp/<token>",
|
|
40
|
+
"port": 47821,
|
|
41
|
+
"token": "<token>",
|
|
42
|
+
"pid": 12345,
|
|
43
|
+
"startedAt": "2026-10-22T12:30:00.000Z"
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`~/.dsh/bridge/endpoint.json`,目录 `0700`,文件 `0600`。
|
|
48
|
+
|
|
49
|
+
## 连接
|
|
50
|
+
|
|
51
|
+
### Codex
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
codex mcp add dsh-bridge --url "$(node -p "require(process.env.HOME+'/.dsh/bridge/endpoint.json').url")"
|
|
55
|
+
codex mcp list # 验证
|
|
56
|
+
codex mcp remove dsh-bridge # 移除
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
桌面 App 与 CLI 共用 `~/.codex/config.toml`,两端都能看到。token 放在 URL 路径里,因此不需要环境变量——桌面 App 从 Finder 启动时拿不到自定义环境变量。也支持 `Authorization: Bearer <token>`。
|
|
60
|
+
|
|
61
|
+
### Claude Code
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
claude mcp add --transport http dsh-bridge "<上面那个 url>" --scope user
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 用法
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
// 同步:等这一轮跑完,直接拿答案
|
|
71
|
+
dsh_task({ prompt: "审一下 src/bridge.ts 的错误处理", cwd: "/repo" })
|
|
72
|
+
|
|
73
|
+
// 异步:先派活,再一起等
|
|
74
|
+
dsh_spawn({ task_name: "audit_api", message: "…", cwd: "/repo" })
|
|
75
|
+
dsh_spawn({ task_name: "audit_ui", message: "…", cwd: "/repo" })
|
|
76
|
+
dsh_wait({ targets: ["audit_api", "audit_ui"], timeoutMs: 240000 })
|
|
77
|
+
|
|
78
|
+
// 续派:复用已有 worker 的上下文
|
|
79
|
+
dsh_followup({ worker: "audit_api", message: "把第 3 条展开,附上补丁" })
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 工具
|
|
83
|
+
|
|
84
|
+
| 工具 | 作用 |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `dsh_task` | 同步派活:开会话、投递、阻塞到回合结束,返回最终回答 |
|
|
87
|
+
| `dsh_spawn` | 异步派活:立刻返回 `task_name` + `sessionId` |
|
|
88
|
+
| `dsh_followup` | 在已有 worker 上再派一轮,复用其上下文 |
|
|
89
|
+
| `dsh_wait` | 一次等多个 worker,任一到达终态即返回 |
|
|
90
|
+
| `dsh_close` | 关闭 worker 并释放名额(会话保留) |
|
|
91
|
+
| `dsh_answer` | 回答 worker 提出的问题(有已知限制,见下) |
|
|
92
|
+
| `dsh_list_workers` | 列出本桥开的 worker 及实时状态 |
|
|
93
|
+
| `dsh_dispatch` | 向任意会话投递一条消息;返回 `requestId` 与 `seqAtDispatch` |
|
|
94
|
+
| `dsh_read_result` | 长轮询读取 `seqAtDispatch` 之后产生的助手文本 |
|
|
95
|
+
| `dsh_list_sessions` | 只列会话元数据(id、标题、cwd、是否运行、最后活动时间) |
|
|
96
|
+
|
|
97
|
+
`dsh_list_sessions` 从不返回消息内容;`dsh_read_result` 只对本桥派发过的会话有效。
|
|
98
|
+
|
|
99
|
+
### 指定模型
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
dsh_task({ prompt: "…", model: "zai-coding-cn/glm-5.3", reasoningEffort: "max" })
|
|
103
|
+
dsh_spawn({ task_name: "review", message: "…", model: "opencode-go/deepseek-v4.1-flash" })
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- 写法是 `provider/model`;只写模型名时沿用当前默认 provider。
|
|
107
|
+
- `reasoningEffort` 可选,取值随模型。
|
|
108
|
+
- 不传则完全不动会话。
|
|
109
|
+
- 切换发生在第一次 prompt 之前,所以 worker 第一轮就已经在新模型上跑,且不会改动 profile 的默认模型。
|
|
110
|
+
|
|
111
|
+
### 项目归属
|
|
112
|
+
|
|
113
|
+
DSH 把会话分组为项目;新建会话默认落在「未分组」,除非所在目录已经是项目。
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
dsh_task({ prompt: "…", cwd: "/repo/clawer", workspace: true }) // 创建,标题取目录名
|
|
117
|
+
dsh_spawn({ task_name: "w1", message: "…", cwd: "/repo/clawer", workspace: "Clawer" })
|
|
118
|
+
dsh_task({ prompt: "…", cwd: "/repo/clawer" }) // 只复用
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
目录不存在会先创建(登记要求目录已存在)。已是项目则复用且**不改标题**。返回里带 `workspace: { id, title, path }`。项目操作失败不会让派发失败。
|
|
122
|
+
|
|
123
|
+
### 排队或插话
|
|
124
|
+
|
|
125
|
+
DSH 的「繁忙时的发送行为」只有两种:
|
|
126
|
+
|
|
127
|
+
| `mode` | 行为 |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `queue`(默认) | 等当前回合结束,作为新回合投递 |
|
|
130
|
+
| `steer` | 插入当前回合,模型在下一步就能看到 |
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
dsh_followup({ worker: "w1", message: "接下来只改 src 下的文件", mode: "steer" })
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
两个实测结论:
|
|
137
|
+
|
|
138
|
+
1. **`steer` 不打断正在执行的工具调用。** worker 若正卡在 `sleep 90` 里,要等那次调用返回才看得到消息(实测 70 秒)。真的停下是界面上的「取消」,不是投递模式。
|
|
139
|
+
2. **`steer` 不新开回合** —— turn 编号不变,所以桥等的是**当前**回合结束;等「下一个回合」会一直阻塞到超时。
|
|
140
|
+
|
|
141
|
+
`dsh_task` 对运行中的会话默认拒绝,除非传 `mode: "steer"`,错误信息里也这么写。插话的回复与原任务同一回合,所以桥以**自己那条用户消息**为锚点取回答,而不是这一轮最后一条助手文本。
|
|
142
|
+
|
|
143
|
+
### 无人值守
|
|
144
|
+
|
|
145
|
+
调用 `ask_user_question` 的 worker 会等人回答。调用方是另一个 agent 时,没有人在这。因此桥给每个派发的任务追加一条常驻指令:
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
(如果缺少必要信息或需要在多个方案里选择,直接采用最合理的默认做法继续做完,
|
|
149
|
+
不要把选择权抛回给用户、不要调用 ask_user_question 等回答;
|
|
150
|
+
在结果里用一行说明你假设了什么。)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
默认开启(`assumeDefaults: false` 可关闭)。prompt 里本来就提到 `ask_user_question` 时不追加。
|
|
154
|
+
|
|
155
|
+
想换成自己的措辞——比如英文——用 `assumptionPolicy`:
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
config:
|
|
159
|
+
assumptionPolicy: "If information is missing, pick the most reasonable default, finish the task, and state the assumption in one line. Do not ask the user or call ask_user_question."
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 问题上报
|
|
163
|
+
|
|
164
|
+
worker 真的提问时,`dsh_wait` 会把问题带出来:
|
|
165
|
+
|
|
166
|
+
```jsonc
|
|
167
|
+
{
|
|
168
|
+
"status": { "w1": "running" },
|
|
169
|
+
"pendingQuestion": {
|
|
170
|
+
"callId": "call_abc",
|
|
171
|
+
"questions": [{ "id": "mode", "question": "用哪种模式?", "options": [{ "label": "快速" }] }]
|
|
172
|
+
},
|
|
173
|
+
"next": "blocked on a question: answer it with dsh_answer, or call dsh_wait again"
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`dsh_answer({ worker, answers: [{ id: "mode", selected: ["快速"] }] })` 提交答案。
|
|
178
|
+
|
|
179
|
+
**已知限制:** DSH 的 `userQuestions.answer()` 只接受已经超时进入 `continued` 状态的问题。仍阻塞在工具调用里的问题由 Web UI 的 answerer 接管,桥答不了(实测返回 `answered: false`)。实际使用中应依赖 `assumeDefaults`,而不是等 worker 提问。
|
|
180
|
+
|
|
181
|
+
## 反向方向
|
|
182
|
+
|
|
183
|
+
两个工具都注册给本部署的 Agent。
|
|
184
|
+
|
|
185
|
+
### `codex_dispatch`
|
|
186
|
+
|
|
187
|
+
| 参数 | 说明 |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `prompt` | 必填,任务正文 |
|
|
190
|
+
| `cwd` | 工作目录;默认用调用方会话的目录 |
|
|
191
|
+
| `resume` | Codex 线程 id,用于续接 |
|
|
192
|
+
| `sandbox` | `read-only` / `workspace-write` / `danger-full-access` |
|
|
193
|
+
|
|
194
|
+
返回 `{ ok, text, threadId, exitCode, durationMs }`。执行 `codex exec [resume <id>] --json -o <临时文件>`,从事件流读 `thread.started`,从 `-o` 文件读最终消息。**`resume` 时 `sandbox` 与 `cwd` 均不生效** —— `codex exec resume` 不接受这两个参数。
|
|
195
|
+
|
|
196
|
+
### `claude_dispatch`
|
|
197
|
+
|
|
198
|
+
| 参数 | 说明 |
|
|
199
|
+
| --- | --- |
|
|
200
|
+
| `prompt` | 必填,任务正文 |
|
|
201
|
+
| `cwd` | 工作目录 |
|
|
202
|
+
| `resume` | Claude Code 的 session id |
|
|
203
|
+
| `model` | 模型别名或 id;不传则用配置,再退回 CLI 自己的设置 |
|
|
204
|
+
|
|
205
|
+
返回 `{ ok, text, sessionId, durationMs }`。执行 `claude -p --output-format json`,只读 stdout 上的单个 JSON 对象。**stderr 只是提示** —— 模型名后缀不被识别时 CLI 会警告,但结果仍然正常。
|
|
206
|
+
|
|
207
|
+
## 配置
|
|
208
|
+
|
|
209
|
+
```yaml
|
|
210
|
+
- insert:
|
|
211
|
+
- id: subagent-bridge
|
|
212
|
+
name: 'dsh-plugin-subagent-bridge'
|
|
213
|
+
config:
|
|
214
|
+
port: 47821
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
| 键 | 默认 | 说明 |
|
|
218
|
+
| --- | --- | --- |
|
|
219
|
+
| `enabled` | `true` | 总开关;关闭后不监听、不写端点文件 |
|
|
220
|
+
| `port` | `47821` | 回环端口;固定端口让客户端 URL 重启后依然有效 |
|
|
221
|
+
| `endpointFile` | `~/.dsh/bridge/endpoint.json` | 端点与令牌写入位置 |
|
|
222
|
+
| `maxResultChars` | `20000` | 单次结果载荷上限(保留开头) |
|
|
223
|
+
| `taskTimeoutSeconds` | `300` | `dsh_task` 等待上限(客户端可覆盖,最大 240) |
|
|
224
|
+
| `assumeDefaults` | `true` | 追加「自行决策」指令 |
|
|
225
|
+
| `assumptionPolicy` | 空 | 替换指令正文;空表示用内置中文默认 |
|
|
226
|
+
| `workersFile` | `~/.dsh/bridge/workers.json` | worker 注册表(`0600`) |
|
|
227
|
+
| `maxHops` | `1` | 委派深度上限 |
|
|
228
|
+
| `dispatchPerMinute` | `10` | 每个窗口允许的派发次数 |
|
|
229
|
+
| `dispatchWindowMs` | `60000` | 窗口长度 |
|
|
230
|
+
| `maxWorkersPerRoot` | `4` | 每个工作目录的 worker 上限 |
|
|
231
|
+
| `maxWorkers` | `12` | 全局 worker 上限 |
|
|
232
|
+
| `workerTtlMs` | `86400000` | 记录过期后不再占名额 |
|
|
233
|
+
| `waitTimeoutMs` | `240000` | `dsh_wait` 默认超时 |
|
|
234
|
+
| `readWaitSeconds` | `25` | `dsh_read_result` 默认长轮询时长 |
|
|
235
|
+
| `codexBin` | `codex` | Codex 可执行文件;含 `/` 时严格按路径解析 |
|
|
236
|
+
| `codexSandbox` | `workspace-write` | `codex_dispatch` 默认 sandbox |
|
|
237
|
+
| `codexTimeoutMs` | `300000` | 单次运行超时 |
|
|
238
|
+
| `claudeBin` | `claude` | Claude Code 可执行文件 |
|
|
239
|
+
| `claudeModel` | 空 | 空表示用 CLI 自己的设置 |
|
|
240
|
+
| `claudeTimeoutMs` | `300000` | 单次运行超时 |
|
|
241
|
+
|
|
242
|
+
端口被占用时会**报错而不是静默换端口**:端点文件里写入 `error` 字段,宿主日志打印 `subagent-bridge: could not start on port …`。
|
|
243
|
+
|
|
244
|
+
## 护栏
|
|
245
|
+
|
|
246
|
+
**深度。** 两个 agent 都能看到同一个桥,因此存在环路:DSH worker → `codex_dispatch` → 那次 Codex → `dsh_spawn` → … 每次派发都计算 `max(在飞链路深度, 调用方深度) + 1`,超过 `maxHops` 直接拒绝:
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
codex_dispatch would create delegation depth 2, but maxHops is 1.
|
|
250
|
+
Carry the work out directly instead of delegating again.
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**速率。** `dispatchPerMinute`(默认 10)拦截突发与紧循环重试:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
rate limit: 10 dispatches per 60s reached; retry in 23s
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**名额。** 每个 `cwd` 4 个,全局 12 个。完成的 worker 在 `dsh_close` 之前仍占名额;记录超过 24 小时自动不再计数。阻塞式 `dsh_task` 只登记、不占名额。按 `cwd` 分桶是因为 MCP 端点共享且请求里没有会话身份。
|
|
260
|
+
|
|
261
|
+
**持久化。** `workers.json` 保存注册表与每轮基线:重启后 worker 仍在,已完成的直接回放缓存答案,冷会话报告 `offline`,文件最多保留 200 条。
|
|
262
|
+
|
|
263
|
+
**安全。** 只监听回环;每个请求都要令牌(路径或 bearer 头),常量时间比较;令牌只生成一次并持久化。拿到端点文件等价于能向会话投递消息——保持 `0600`/`0700` 权限。DSH 自身的 sandbox 与审批规则对投递内容依然生效。
|
|
264
|
+
|
|
265
|
+
## 工作原理
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
Codex / 任意 MCP 客户端
|
|
269
|
+
│ POST /mcp/<token> JSON-RPC(无状态,单次 JSON 响应)
|
|
270
|
+
▼
|
|
271
|
+
dsh-plugin-subagent-bridge(宿主进程内)
|
|
272
|
+
· node:http 监听 127.0.0.1:47821
|
|
273
|
+
· initialize / tools/list / tools/call / ping
|
|
274
|
+
· sessionController.prompt({ sessionId, requestId, mode, content })
|
|
275
|
+
· sessions.get(id).snapshotEvents() 读回文本
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
协议是 streamable HTTP 的无状态子集:每个 POST 返回一个 `application/json`,没有任何推送,所以结果靠长轮询取。客户端一断开,服务端立刻停止等待。
|
|
279
|
+
|
|
280
|
+
## 配套 skill
|
|
281
|
+
|
|
282
|
+
两份可安装的 skill 把这些能力变成模型会遵循的行为,而不是它可能忘记的工具:
|
|
283
|
+
|
|
284
|
+
| Skill | 装给谁 | 作用 |
|
|
285
|
+
| --- | --- | --- |
|
|
286
|
+
| `deepseek-worker` | Codex | Codex 何时、如何把任务派给 DSH |
|
|
287
|
+
| `delegate-to-external-agent` | DSH | DSH 何时该派给 Codex 或 Claude Code |
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
mkdir -p ~/.codex/skills && cp -R skills/deepseek-worker ~/.codex/skills/
|
|
291
|
+
mkdir -p ~/.dsh/skills && cp -R skills/delegate-to-external-agent ~/.dsh/skills/
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
两份都是普通 `SKILL.md`:YAML frontmatter(`name` + `description`)加正文。触发全靠 description,所以里面写了中英触发语和明确的「不要用」边界。改完不用重启即刻生效。
|
|
295
|
+
|
|
296
|
+
## 兼容性
|
|
297
|
+
|
|
298
|
+
- DSH `^0.2.1-0`(`engines.dsh`)。
|
|
299
|
+
- MCP 协议版本 `2025-06-18`、`2025-03-26`、`2024-11-05`;未知版本回落到最新。
|
|
300
|
+
- 依赖公开服务 `sessionController`、`sessions`、`workspaceRegistry`、`userQuestions`;缺失时以明确的工具错误呈现。
|
|
301
|
+
|
|
302
|
+
## 开发
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
node --test "test/*.test.mjs"
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
83 项测试:握手与版本协商、工具清单与参数校验、派发调用形状、结果基线、长轮询、真实 HTTP 往返(404/405/202 与 bearer)、`codex exec` 事件解析、二进制解析、成功/失败/超时、resume 参数分叉、只回最终回答、`dsh_wait` 终态、名额上限与释放、followup 重基线、注册表持久化与重启恢复、`maxHops` 与速率限制、按 `cwd` 的预算、项目创建与复用、`queue`/`steer` 投递与等待、插话回答的锚点、Claude 输出解析与 resume 参数、`assumeDefaults` 注入、`pendingQuestion` 与 `dsh_answer`。
|
|
309
|
+
|
|
310
|
+
## 相关插件
|
|
311
|
+
|
|
312
|
+
| 插件 | 说明 |
|
|
313
|
+
| --- | --- |
|
|
314
|
+
| **dsh-plugin-subagent-bridge**(本仓库) | 让 Codex 把 DSH 当 subagent 用,DSH 也能派给 Codex / Claude Code |
|
|
315
|
+
| [dsh-plugin-composer-predict](https://github.com/Dogtiti/dsh-plugin-composer-predict) | 预测下一条指令并显示为占位文字,`Tab` 采纳 |
|
|
316
|
+
| [dsh-plugin-composer-history](https://github.com/Dogtiti/dsh-plugin-composer-history) | 输入框中按 `↑` / `↓` 回填历史消息 |
|
|
317
|
+
| [dsh-plugin-usage-panel](https://github.com/Dogtiti/dsh-plugin-usage-panel) | 在模型选择器旁显示供应商额度余量 |
|
|
318
|
+
| [dsh-plugin-provider-icons](https://github.com/Dogtiti/dsh-plugin-provider-icons) | 在模型名旁显示供应商品牌 logo |
|
|
319
|
+
|
|
320
|
+
## 许可
|
|
321
|
+
|
|
322
|
+
MIT © [Dogtiti](https://github.com/Dogtiti)
|
package/index.js
CHANGED
|
@@ -76,6 +76,7 @@ const DEFAULTS = {
|
|
|
76
76
|
codexSandbox: 'workspace-write',
|
|
77
77
|
codexTimeoutMs: 300000,
|
|
78
78
|
assumeDefaults: true,
|
|
79
|
+
assumptionPolicy: '',
|
|
79
80
|
claudeBin: 'claude',
|
|
80
81
|
claudeModel: '',
|
|
81
82
|
claudeTimeoutMs: 300000,
|
|
@@ -329,7 +330,9 @@ const ASSUMPTION_POLICY =
|
|
|
329
330
|
function withAssumptionPolicy(settings, message) {
|
|
330
331
|
if (settings.assumeDefaults !== true) return message
|
|
331
332
|
if (message.includes('ask_user_question')) return message
|
|
332
|
-
|
|
333
|
+
const custom = typeof settings.assumptionPolicy === 'string' ? settings.assumptionPolicy.trim() : ''
|
|
334
|
+
const policy = custom === '' ? ASSUMPTION_POLICY : custom
|
|
335
|
+
return `${message}\n\n(${policy})`
|
|
333
336
|
}
|
|
334
337
|
|
|
335
338
|
/**
|
|
@@ -2336,6 +2339,10 @@ function resolveSettings(config) {
|
|
|
2336
2339
|
merged.assumeDefaults = value === true || value === 'true'
|
|
2337
2340
|
continue
|
|
2338
2341
|
}
|
|
2342
|
+
if (key === 'assumptionPolicy' && typeof value === 'string') {
|
|
2343
|
+
merged.assumptionPolicy = value.trim()
|
|
2344
|
+
continue
|
|
2345
|
+
}
|
|
2339
2346
|
if (key === 'claudeBin' && typeof value === 'string' && value !== '') merged.claudeBin = value
|
|
2340
2347
|
if (key === 'claudeModel' && typeof value === 'string') merged.claudeModel = value
|
|
2341
2348
|
if (key === 'workersFile' && typeof value === 'string' && value !== '') merged.workersFile = expandHome(value)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-subagent-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Subagent bridge: lets Codex delegate a task to DeepSeek Harness the way it would spawn a subagent (one call, waits for the answer), plus a codex_dispatch tool for the reverse direction.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"cordis.patch.yml",
|
|
29
29
|
"locale/*.json",
|
|
30
30
|
"icon.svg",
|
|
31
|
-
"skills/*/SKILL.md"
|
|
31
|
+
"skills/*/SKILL.md",
|
|
32
|
+
"README.md",
|
|
33
|
+
"README.zh-CN.md"
|
|
32
34
|
],
|
|
33
35
|
"engines": {
|
|
34
36
|
"dsh": "^0.2.1-0"
|