dsh-baton-mcp 0.6.8 → 0.6.10
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 +2 -2
- package/README.zh-CN.md +2 -2
- package/host/package.json +2 -2
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/cli.mjs +13 -2
- package/src/core.mjs +99 -11
- package/src/mcp.mjs +10 -3
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Switched on, the plugin registers dsh-baton for Claude Code and Codex, for every
|
|
|
53
53
|
|
|
54
54
|
That is all. To hand a task over, end the request with "hand it to DeepSeek Harness". Updating, removing, Windows, and registering by hand when the plugin could not, are [further down](#install-details).
|
|
55
55
|
|
|
56
|
-
**
|
|
56
|
+
**Installed on the day of a release?** For about a day after a release, Harness installs the previous version, and its install dialog says so. Open the plugin's page and press **Update to x.y.z** (更新到), or add the plugin with its version, such as `dsh-baton-host@0.6.8`.
|
|
57
57
|
|
|
58
58
|
<p align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="./assets/readme/en/divider-dark.svg"><img src="./assets/readme/en/divider.svg" width="100%" alt=""></picture></p>
|
|
59
59
|
|
|
@@ -284,7 +284,7 @@ When you update or remove the plugin, come from dsh-bridge, run from source, or
|
|
|
284
284
|
|
|
285
285
|
**`npx -y dsh-baton-mcp setup`** does the same registration from a terminal: for a plugin that could not register, or when you come from an MCP directory. With the plugin already registered it changes nothing, then points you to the plugin if it is missing.
|
|
286
286
|
|
|
287
|
-
**Updating.** Harness
|
|
287
|
+
**Updating.** On Harness 0.2.2 and later: Plugins → dsh-baton-host → **Update to x.y.z** (更新到) under Version; if it still says up to date, press **Check again** (重新检查) first. Harness 0.2.1 has no update button for this plugin: **Uninstall**, then **Add plugin** → `dsh-baton-host`. For about a day after a release, Harness installs the previous version instead (pnpm's `minimumReleaseAge` holds back versions published very recently, and the install dialog says so); to get the new one at once, type the version: `dsh-baton-host@0.6.8`. A pre-release must always be added by its exact version, such as `dsh-baton-host@0.6.0-next.0`: Harness resolves `@next` to a broken placeholder. Plain `dsh-baton-host` gets the latest release. Switched on again, the plugin brings the MCP server to the same version; new conversations use it. If the two are ever out of step, the first tool call that notices it says so, naming the older side and the newer side's exact version to install.
|
|
288
288
|
|
|
289
289
|
**Removing.** Harness → Plugins → dsh-baton-host → **Uninstall**, then `npx -y dsh-baton-mcp setup --remove`. The plugin cannot tell an uninstall from Harness quitting, so it leaves the MCP entries to that command, which also deletes `~/.dsh-baton/app`; run records stay in `~/.dsh-baton` until you delete it.
|
|
290
290
|
|
package/README.zh-CN.md
CHANGED
|
@@ -53,7 +53,7 @@ dsh-baton 是一个 MCP 服务器加一个 Harness 小插件。主 Agent 用一
|
|
|
53
53
|
|
|
54
54
|
就这些。要转交任务,在需求最后加一句“交给 DeepSeek Harness 去做”。更新、卸载、Windows,以及插件没能注册时怎么手动注册,在[后面](#安装细节)。
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
**刚发版就安装?** 新版本发布后大约一天内,Harness 会装上一个版本,安装弹窗里会说明。打开插件详情页点 **更新到 x.y.z**,或者添加插件时带上版本号,比如 `dsh-baton-host@0.6.8`。
|
|
57
57
|
|
|
58
58
|
<p align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="./assets/readme/zh/divider-dark.svg"><img src="./assets/readme/zh/divider.svg" width="100%" alt=""></picture></p>
|
|
59
59
|
|
|
@@ -284,7 +284,7 @@ Harness 插件连不上时:
|
|
|
284
284
|
|
|
285
285
|
**`npx -y dsh-baton-mcp setup`** 在终端里做同样的注册:用于插件没能注册的情况,或者从 MCP 目录过来的用户。插件已经注册过时它什么都不改;插件没装的话,它会提示去添加。
|
|
286
286
|
|
|
287
|
-
**更新**。Harness
|
|
287
|
+
**更新**。Harness 0.2.2 及以上:插件 → dsh-baton-host → 版本一栏里的 **更新到 x.y.z**;如果还显示已是最新版本,先点 **重新检查**。Harness 0.2.1 没有这个插件的更新按钮:**卸载**,再**添加插件** → `dsh-baton-host`。新版本发布后大约一天内,Harness 会装上一个版本(pnpm 的 `minimumReleaseAge` 会暂缓刚发布的版本,安装弹窗里会说明);想马上用新版,输入带版本号的名字:`dsh-baton-host@0.6.8`。预发布版必须写确切版本号添加,比如 `dsh-baton-host@0.6.0-next.0`:Harness 会把 `@next` 解析成一个坏掉的占位包。只输入 `dsh-baton-host` 装的是最新正式版。重新启用后,插件会把 MCP 服务器也更新到同一版本,新开的对话就会用上。万一两边版本对不上,第一次发现不一致的工具调用会提示,并写明哪一边旧、另一边的确切版本号。
|
|
288
288
|
|
|
289
289
|
**卸载**。Harness → 插件 → dsh-baton-host → **卸载**,再运行 `npx -y dsh-baton-mcp setup --remove`。插件分不清"被卸载"和"Harness 退出",所以 MCP 注册交给这条命令删,它也会删掉 `~/.dsh-baton/app`;运行记录留在 `~/.dsh-baton`,不需要的话自己删掉。
|
|
290
290
|
|
package/host/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-baton-host",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "DeepSeek Harness plugin for dsh-baton: hand coding tasks from Claude Code or Codex to DeepSeek Harness on your machine. Adding it is the whole install: it registers the dsh-baton MCP server for Claude Code and Codex, runs each task live in the Harness window, wakes the main agent when the run ends and hands back the changed files, the project's own test results and a requirement-by-requirement checklist.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"dsh-baton-mcp": "0.6.
|
|
23
|
+
"dsh-baton-mcp": "0.6.10"
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dsh": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-baton-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"mcpName": "io.github.JialaoLiu/dsh-baton",
|
|
5
5
|
"description": "Pass the baton from Claude Code, Codex or any MCP client to a local DeepSeek Harness: an MCP server that hands off tasks, continues a specific session, shows the run live in Harness and hands the result back when it is done.",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"url": "https://github.com/JialaoLiu/dsh-baton",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.6.
|
|
10
|
+
"version": "0.6.10",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "dsh-baton-mcp",
|
|
15
|
-
"version": "0.6.
|
|
15
|
+
"version": "0.6.10",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
package/src/cli.mjs
CHANGED
|
@@ -91,6 +91,7 @@ async function main() {
|
|
|
91
91
|
const total_s = Number(flags.timeout) || 24 * 3600
|
|
92
92
|
const waitStarted = Date.now()
|
|
93
93
|
const st = await core.api.wait({ run_id: rest[0], timeout_s: total_s })
|
|
94
|
+
const stop = core.stopHint(st)
|
|
94
95
|
// A Harness goal goes on after the run's own round: so does this wait, until the goal
|
|
95
96
|
// stops (or the next report, with --until turn), with every round since the run began.
|
|
96
97
|
if (core.goalGoesOn(st)) {
|
|
@@ -105,15 +106,25 @@ async function main() {
|
|
|
105
106
|
process.exitCode = f.state === 'needs_input' ? 3 : 0
|
|
106
107
|
return
|
|
107
108
|
}
|
|
109
|
+
if (st.needs_input && st.question) {
|
|
110
|
+
const { run_id, state, session_id, needs_input, question } = st
|
|
111
|
+
print(core.asking({ run_id, state, session_id, needs_input, question }, core.askHint(question.count ?? question.questions?.length ?? 1, 'dsh_answer (or dsh-baton answer)', 'wait again')))
|
|
112
|
+
process.exitCode = 3
|
|
113
|
+
return
|
|
114
|
+
}
|
|
108
115
|
print({
|
|
109
|
-
...(st.decided_for_user ? { hint:
|
|
116
|
+
...(st.decided_for_user ? { hint: `${core.DECIDED_HINT} ${core.endedHint(st)}`, decided_for_user: st.decided_for_user } : {}),
|
|
110
117
|
run_id: st.run_id, state: st.state, session_id: st.session_id, timed_out: !!st.timed_out, error: st.error, final_text: st.final_text,
|
|
111
118
|
// A goal goes on after this run: the hint says so and how to follow it.
|
|
112
119
|
...(st.goal ? { goal: st.goal, ...(st.goal.phase === 'active' ? { follow_command: self(`follow ${st.session_id}`) } : {}) } : {}),
|
|
113
120
|
// The hint points at evidence: it goes with it (files changed, checks run, other runs in the folder).
|
|
114
121
|
...(st.evidence ? { evidence: st.evidence } : {}),
|
|
115
122
|
...(st.state === 'completed' && !st.decided_for_user ? { hint: core.endedHint(st) } : {}),
|
|
116
|
-
|
|
123
|
+
// Stopped by the user, cancelled, or cut off by a Harness restart: say so, or the client
|
|
124
|
+
// takes it for a failure in the work and sends it again.
|
|
125
|
+
...(st.harness_down ? { harness_down: true, hint: core.harnessDownHint('run this same wait command again') } : {}),
|
|
126
|
+
...(stop ? { ...(st.turn_end ? { turn_end: st.turn_end } : {}), ...stop } : {}),
|
|
127
|
+
...(st.needs_input ? { needs_input: st.needs_input, hint: 'The run waits for a person in the Harness UI. Tell the user, then wait again.' } : {}) })
|
|
117
128
|
process.exitCode = st.state === 'completed' ? 0 : st.needs_input ? 3 : 1
|
|
118
129
|
return
|
|
119
130
|
}
|
package/src/core.mjs
CHANGED
|
@@ -147,7 +147,8 @@ function hostCallAt(endpoint, method, params = {}, { timeoutMs = 15000 } = {}) {
|
|
|
147
147
|
msg.error ? finish(new Error(String(msg.error))) : finish(null, msg.result)
|
|
148
148
|
})
|
|
149
149
|
conn.on('error', (e) => finish(Object.assign(e, { hostDown: true })))
|
|
150
|
-
|
|
150
|
+
// Harness quitting closes the connection mid-call: marked so a wait can wait for it to come back.
|
|
151
|
+
conn.on('close', () => finish(Object.assign(new Error(`dsh-baton-host closed the connection before answering ${method}`), { hostClosed: true })))
|
|
151
152
|
})
|
|
152
153
|
}
|
|
153
154
|
|
|
@@ -603,7 +604,7 @@ export function followResult(st) {
|
|
|
603
604
|
case 'following': return { ...st, hint: `No report is due yet: ${AGAIN}, with no progress note in between. ${QUIET}` }
|
|
604
605
|
case 'goal_ended': return { ...st, hint: `The goal stopped (${st.ended_because}${st.goal?.blocked_reason ? `: ${st.goal.blocked_reason.message}` : ''}), so following is over. ${report}${st.ended_because === 'blocked' || st.ended_because === 'paused' ? ' It needs the user before it goes on: say so.' : ''}` }
|
|
605
606
|
case 'needs_input': return st.question
|
|
606
|
-
?
|
|
607
|
+
? asking(st, askHint(st.question.count, `dsh_answer and session_id ${st.session_id} (no run_id)`, AGAIN))
|
|
607
608
|
: { ...st, hint: `Harness waits for something only a person can do in its window (an approval, for example). Tell the user, then ${AGAIN}.` }
|
|
608
609
|
case 'needs_resume': return { ...st, hint: 'The goal is still active, but Harness will not go on with it by itself (for example after a Harness restart). Tell the user to press Continue in Harness, and stop following until they have.' }
|
|
609
610
|
case 'goal_stalled': return { ...st, hint: 'The goal is active, yet no new round has started for 5 minutes: Harness may have stopped going on with it (for example after a restart). Tell the user; they can press Continue in Harness. Stop following until they have.' }
|
|
@@ -617,11 +618,51 @@ export const QUOTA_HINT = 'The run stopped because the DeepSeek account has no b
|
|
|
617
618
|
const outOfBalance = (st) => st.state === 'failed' && (['ACCOUNT_QUOTA', 'QUOTA'].includes(st.turn_end?.error?.code) || st.turn_end?.error?.status === 402 || /insufficient balance/i.test(st.error ?? ''))
|
|
618
619
|
|
|
619
620
|
// What to do when a run stops to ask a person (dsh_wait, wait_command and the instructions say it).
|
|
620
|
-
|
|
621
|
-
|
|
621
|
+
// The options are the asking model's guesses, not the limit of the answer: every question also
|
|
622
|
+
// takes free text (on a single-choice question it replaces the option, Harness's own rule).
|
|
623
|
+
// The user wants the client to decide as the owner of the task, not pick the least bad option.
|
|
624
|
+
export const OWN_WORDS = 'On a single choice, text replaces the option.'
|
|
625
|
+
export const ASKED = `If the user told you to decide such questions yourself, decide as the task's owner: an option only if it fits as is, else your own words. ${OWN_WORDS} Call dsh_answer with a one-sentence reason, then tell the user what you answered and why. Otherwise relay the questions, starting with your advice on its own line: "My recommendation: <an option, or your own answer>, because <reason>", from your own judgment, even outside the options (harness_suggested is only the asker's pick, never a reason). List the options (the user may also answer in words) and submit their decision with dsh_answer. Never answer on the user's behalf without that permission.`
|
|
626
|
+
export const DECIDED_HINT = 'Required in your reply: you answered for the user during this run, so start your reply by telling the user, in their language, what you answered (an option or your own words) and why (decided_for_user: answers and reason), then give the result. Passing on only final_text is not enough.'
|
|
627
|
+
// What to do when a run asks the user, in one short hint that goes first in the result.
|
|
628
|
+
// Codex relays through its own question tool (request_user_input: a title and plain option
|
|
629
|
+
// strings); the message before that call is folded away in the Codex app, so a recommendation
|
|
630
|
+
// written only there is lost (Mac, 2026-11-08), and longer hints did not change that. The
|
|
631
|
+
// result therefore carries question_tool, the call laid out with the recommendation as its first
|
|
632
|
+
// option, as relay is the message laid out with it as its first line: clients copy a layout
|
|
633
|
+
// more reliably than they follow rules.
|
|
634
|
+
export const askHint = (n, answerWith, then) => `Harness asks the user ${n} question(s). If the user let you decide such questions, answer as the task's owner: an option only if it fits as is, else your own words (text; ${OWN_WORDS.toLowerCase().replace(/\.$/, '')}). An option that needs a note, a fix or an explanation to work for this task does not fit: write the answer it should have been instead. Answer with ${answerWith} and a one-sentence reason, then tell the user what you answered and why. Otherwise ask the user, your own recommendation first: fill the first line of relay (in a message) or the first option of question_tool (in a question tool such as request_user_input) with the answer that best fits this task, checked against its file names and requirements (an option, or your own answer when none fits), and why. Never "your choice", nor the asker's pick (harness_suggested) unchecked. If they pick your recommendation, submit the answer alone, without "Recommended" or the reason. Submit their answer with ${answerWith}, then ${then}.`
|
|
622
635
|
const NEEDS_INPUT_HINT = (st) => st.question
|
|
623
|
-
?
|
|
636
|
+
? askHint(st.question.count, 'dsh_answer', 'wait for the run again')
|
|
624
637
|
: 'The run waits for something only a person can do in the Harness UI (an approval, for example). Tell the user, then wait for the run again.'
|
|
638
|
+
// The hint first, then the question laid out two ways, then the rest of the status.
|
|
639
|
+
export function asking(st, hint) {
|
|
640
|
+
const { hint: _old, relay: _r, question_tool: _q, ...rest } = st
|
|
641
|
+
return { hint, ...(st.question ? { relay: relayText(st.question), question_tool: questionTool(st.question) } : {}), ...rest }
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// A run the user stopped in the Harness UI: its turn ended aborted, by the user. With the usual
|
|
645
|
+
// hint, Codex took that for a failure and sent the task again each time the user stopped it
|
|
646
|
+
// (Windows, 2026-11-08). The UI stop leaves background jobs of the session running; dsh_cancel
|
|
647
|
+
// stops them too.
|
|
648
|
+
export const stoppedByUser = (st) => st?.state === 'failed' && st.turn_end?.kind === 'aborted' && st.turn_end?.reason?.kind === 'user'
|
|
649
|
+
export const USER_STOPPED_HINT = 'The user stopped this run in Harness (stopped_by_user). It is not a failure to repair: do not send it again, continue it or send fixes. Tell the user it was stopped and what evidence shows it got done, then ask what to do next. Background jobs it started may still be running in that session; stop them with dsh_cancel and its session_id only if the user asks.'
|
|
650
|
+
// Ended by something other than the work: Harness restarting under the run, or a cancel (dsh_cancel,
|
|
651
|
+
// or in Harness: the user stopping the session drops its queued messages, or removing one). Sending
|
|
652
|
+
// again on one's own would override the user here too.
|
|
653
|
+
export const INTERRUPTED_HINT = 'Harness restarted or quit while this run was going, and its turn was stopped (interrupted). It is not a failure in the work: do not send it again or continue it on your own. Tell the user Harness was restarted and what evidence shows the run got done, then ask whether to run it again or continue in the same session.'
|
|
654
|
+
export const CANCELLED_HINT = 'This run was cancelled before it finished: with dsh_cancel, or in Harness, where the user stopped the session or removed the queued message. If you did not cancel it yourself, the user did: do not send it again. Tell the user it was cancelled and ask what to do next.'
|
|
655
|
+
// The hint for a run that did not end by its own work, or null for one that did.
|
|
656
|
+
// A run that answered a question for the user before it stopped keeps the sentence telling the
|
|
657
|
+
// client to say so.
|
|
658
|
+
export function stopHint(st) {
|
|
659
|
+
const told = (hint) => (st?.decided_for_user ? `${DECIDED_STOPPED} ${hint}` : hint)
|
|
660
|
+
if (stoppedByUser(st)) return { stopped_by_user: true, hint: told(USER_STOPPED_HINT) }
|
|
661
|
+
if (st?.state === 'interrupted') return { hint: told(INTERRUPTED_HINT) }
|
|
662
|
+
if (st?.state === 'cancelled') return { hint: told(CANCELLED_HINT) }
|
|
663
|
+
return null
|
|
664
|
+
}
|
|
665
|
+
const DECIDED_STOPPED = 'You answered a question for the user during this run: tell the user, in their language, what you answered and why (decided_for_user: answers and reason).'
|
|
625
666
|
|
|
626
667
|
// The result of a run that ended, kept short: the client already knows what it sent, and a
|
|
627
668
|
// completed run's event log is only the work behind final_text (dsh_status still has it).
|
|
@@ -629,6 +670,8 @@ const NEEDS_INPUT_HINT = (st) => st.question
|
|
|
629
670
|
function ended({ recent_events, message_preview, backend, ...st }) {
|
|
630
671
|
const out = { ...st, ...(st.state !== 'completed' && recent_events?.length ? { recent_events: recent_events.slice(-5) } : {}) }
|
|
631
672
|
if (outOfBalance(st)) return { ...out, hint: QUOTA_HINT }
|
|
673
|
+
const stop = stopHint(st)
|
|
674
|
+
if (stop) return { ...out, ...stop }
|
|
632
675
|
// decided_for_user first, so a client that skims to final_text still meets it.
|
|
633
676
|
return st.decided_for_user
|
|
634
677
|
? { hint: `${DECIDED_HINT} ${endedHint(st)}`, decided_for_user: st.decided_for_user, ...out }
|
|
@@ -637,9 +680,7 @@ function ended({ recent_events, message_preview, backend, ...st }) {
|
|
|
637
680
|
|
|
638
681
|
|
|
639
682
|
// What dsh_wait returns for a run that ended or stopped to ask (the Codex Stop hook returns the same).
|
|
640
|
-
export const waitResult = (st) => (st.needs_input
|
|
641
|
-
? { ...st, ...(st.question ? { relay: relayText(st.question) } : {}), hint: NEEDS_INPUT_HINT(st) }
|
|
642
|
-
: ended(st))
|
|
683
|
+
export const waitResult = (st) => (st.needs_input ? asking(st, NEEDS_INPUT_HINT(st)) : ended(st))
|
|
643
684
|
|
|
644
685
|
// The asking model marks its favourite option in the label ("(Recommended)", "(推荐)").
|
|
645
686
|
// Clients relaying the question tended to repeat that mark as their own advice, so the
|
|
@@ -674,7 +715,17 @@ export function relayText(question) {
|
|
|
674
715
|
const asker = q.harness_suggested ? [` (The model in Harness that asked would pick: ${q.harness_suggested.label})`] : []
|
|
675
716
|
return [head, ...options, ...asker].join('\n')
|
|
676
717
|
})
|
|
677
|
-
return ['
|
|
718
|
+
return [RECOMMEND_LINE, '', ...blocks, '', 'You can also answer in your own words.'].join('\n')
|
|
719
|
+
}
|
|
720
|
+
const RECOMMEND_LINE = 'My recommendation: <an option, or your own answer>, because <your own reason>'
|
|
721
|
+
// The same questions as a question tool takes them (a title, plain option strings), the first
|
|
722
|
+
// option left for the client's recommendation; the user can still type their own answer there.
|
|
723
|
+
export function questionTool(question) {
|
|
724
|
+
if (!Array.isArray(question?.questions)) return undefined
|
|
725
|
+
return question.questions.map((q) => ({
|
|
726
|
+
title: `${q.question}${q.multi_select ? ' (several can be chosen)' : ''}`,
|
|
727
|
+
options: ['Recommended: <an option, or your own answer>, because <your own reason>', ...(q.options ?? []).map((o) => o.label)],
|
|
728
|
+
}))
|
|
678
729
|
}
|
|
679
730
|
|
|
680
731
|
// When the client chose for the user (dsh_answer with reason), the choice and reason are
|
|
@@ -683,6 +734,23 @@ export function relayText(question) {
|
|
|
683
734
|
// from another process (wait_command).
|
|
684
735
|
const reasonsFile = () => path.join(config.batonHome, 'answer-reasons.json')
|
|
685
736
|
const readReasons = () => { try { return JSON.parse(fs.readFileSync(reasonsFile(), 'utf8')) } catch { return {} } }
|
|
737
|
+
// A client deciding for the user picked the least bad option and patched it with a note
|
|
738
|
+
// (".doc, but keep it plain text"; "XV:00, with a line saying it means 3 pm"), however the hint
|
|
739
|
+
// put it (Codex, Mac, 2026-11-09). So an option chosen for the user is not sent at once: the
|
|
740
|
+
// first call asks for a second look, and the same answers sent again go through. Own words
|
|
741
|
+
// (text) go through at once, as do answers the user gave (no reason).
|
|
742
|
+
export const OPTION_CHECK_HINT = 'Not sent yet, because you chose an option for the user. First, without looking at the options, write down the answer this user would want for this task, as if Harness had asked with no options at all. Send the option (dsh_answer again with the same answers) only if it says the same as that answer. If it does not, answer with text: your answer. An option you can argue for, or make work with a note or an explanation, is not the answer this user would want.'
|
|
743
|
+
const checked = new Map()
|
|
744
|
+
export function optionCheck(a, reason) {
|
|
745
|
+
if (!(typeof reason === 'string' && reason.trim())) return null
|
|
746
|
+
const picks = (a.answers ?? []).filter((x) => x.choose?.length && !(typeof x.text === 'string' && x.text.trim()))
|
|
747
|
+
if (!picks.length) return null
|
|
748
|
+
const key = JSON.stringify([a.run_id ?? a.session_id, picks.map((x) => [x.id ?? null, x.choose.map(String)])])
|
|
749
|
+
for (const [k, at] of checked) if (Date.now() - at > 30 * 60_000) checked.delete(k)
|
|
750
|
+
if (checked.delete(key)) return null
|
|
751
|
+
checked.set(key, Date.now())
|
|
752
|
+
return { submitted: false, check: picks.map((x) => ({ ...(x.id ? { id: x.id } : {}), choose: x.choose })), hint: OPTION_CHECK_HINT }
|
|
753
|
+
}
|
|
686
754
|
function rememberReason(runId, answers, reason) {
|
|
687
755
|
try {
|
|
688
756
|
const all = readReasons()
|
|
@@ -757,6 +825,12 @@ export async function followThrough(params, { total_s, chunk_s = 300, onChunk, s
|
|
|
757
825
|
}
|
|
758
826
|
}
|
|
759
827
|
|
|
828
|
+
// How often a wait looks for Harness again while it is not running.
|
|
829
|
+
const HOST_RETRY_MS = Number(process.env.DSH_BATON_HOST_RETRY_MS) || 2000
|
|
830
|
+
// again: how to wait once Harness is back (dsh_wait for one run or several, or the CLI command).
|
|
831
|
+
export const harnessDownHint = (again = 'call dsh_wait again with the same run_id') => `DeepSeek Harness is not running (closed, or restarting), so the run cannot be followed right now; Harness ends a running turn when it quits. Do not send the task again. Tell the user Harness is closed and to open it; then ${again}: it reports how the run ended (interrupted, if Harness quit while it ran).`
|
|
832
|
+
export const HARNESS_DOWN_HINT = harnessDownHint()
|
|
833
|
+
|
|
760
834
|
export const api = {
|
|
761
835
|
async workspaces() {
|
|
762
836
|
if (!(await useHost())) throw new Error('Listing workspaces needs the dsh-baton-host plugin running inside DeepSeek Harness.')
|
|
@@ -828,8 +902,20 @@ export const api = {
|
|
|
828
902
|
return changed ? { ...st, changed_files: changed } : st
|
|
829
903
|
},
|
|
830
904
|
async wait({ run_id, timeout_s = 300 }) {
|
|
831
|
-
if (isHostRun(run_id)) return withEvidence(
|
|
832
|
-
|
|
905
|
+
if (!isHostRun(run_id)) return withEvidence(tag('headless', await waitRun(run_id, { timeout_s })))
|
|
906
|
+
// Harness quit or restarting: wait for it to come back within the same call (the plugin then
|
|
907
|
+
// reports the run as interrupted) instead of failing, which had Codex retry every few seconds.
|
|
908
|
+
const deadline = Date.now() + timeout_s * 1000
|
|
909
|
+
for (;;) {
|
|
910
|
+
const left = Math.max(1, Math.ceil((deadline - Date.now()) / 1000))
|
|
911
|
+
try {
|
|
912
|
+
return withEvidence(shaped(tag('host', await hostCall('wait', { run_id, timeout_s: left }, { timeoutMs: (left + 15) * 1000 }))))
|
|
913
|
+
} catch (error) {
|
|
914
|
+
if (!(error?.hostDown || error?.hostClosed)) throw error
|
|
915
|
+
if (Date.now() + HOST_RETRY_MS >= deadline) return { run_id, state: 'unknown', timed_out: true, harness_down: true, backend: 'host' }
|
|
916
|
+
await new Promise((r) => setTimeout(r, HOST_RETRY_MS))
|
|
917
|
+
}
|
|
918
|
+
}
|
|
833
919
|
},
|
|
834
920
|
async cancel({ run_id, session_id }) {
|
|
835
921
|
if (run_id && !isHostRun(run_id)) return tag('headless', cancelRun(run_id))
|
|
@@ -860,6 +946,8 @@ export const api = {
|
|
|
860
946
|
// user, not for Harness.
|
|
861
947
|
async answer({ reason, ...a }) {
|
|
862
948
|
if (!(await useHost())) throw new Error('Answering a question needs the dsh-baton-host plugin running inside DeepSeek Harness.')
|
|
949
|
+
const check = optionCheck(a, reason)
|
|
950
|
+
if (check) return check
|
|
863
951
|
try {
|
|
864
952
|
const result = shaped(await hostCall('answer', a))
|
|
865
953
|
if (!(typeof reason === 'string' && reason.trim())) return result
|
package/src/mcp.mjs
CHANGED
|
@@ -122,6 +122,7 @@ async function waitInChunks({ run_id }, progress, signal, meta) {
|
|
|
122
122
|
// Never spin: a chunk that came back early still takes a moment before the next one.
|
|
123
123
|
if (Date.now() - t0 < 500) await new Promise((r) => setTimeout(r, 500))
|
|
124
124
|
if (Date.now() >= deadline) {
|
|
125
|
+
if (st.harness_down) return { run_id, state: st.state, timed_out: true, harness_down: true, hint: core.HARNESS_DOWN_HINT }
|
|
125
126
|
return {
|
|
126
127
|
run_id, state: st.state, timed_out: true,
|
|
127
128
|
...(st.waiting_on ? { waiting_on: st.waiting_on } : {}),
|
|
@@ -182,6 +183,7 @@ async function waitAnyInChunks(run_ids, progress, signal, meta) {
|
|
|
182
183
|
if (Date.now() - t0 < 500) await new Promise((r) => setTimeout(r, 500))
|
|
183
184
|
if (Date.now() >= deadline) {
|
|
184
185
|
const asking = running.filter((r) => r.state === 'waiting').map((r) => r.run_id)
|
|
186
|
+
if ([...answers.values()].some((st) => st.harness_down)) return { run_ids, timed_out: true, harness_down: true, still_running: running, hint: core.harnessDownHint('call dsh_wait again with the same run_ids') }
|
|
185
187
|
return {
|
|
186
188
|
run_ids, timed_out: true, still_running: running,
|
|
187
189
|
hint: `None of these runs has ended yet. Call dsh_wait again with the same run_ids, with no progress check or progress note in between (work the user asked you to do meanwhile is fine).${asking.length ? ` ${asking.join(', ')} still wait${asking.length === 1 ? 's' : ''} for a person (see dsh_status for the question): answer with dsh_answer if you may, or tell the user.` : ''}`,
|
|
@@ -200,12 +202,15 @@ function anyResult({ done, running }) {
|
|
|
200
202
|
: res
|
|
201
203
|
})
|
|
202
204
|
const ids = running.map((r) => r.run_id)
|
|
205
|
+
// Stopped by the user, cancelled or cut off by a Harness restart: not work to send back.
|
|
206
|
+
const stopped = ended.filter((r) => r.stopped_by_user || r.state === 'interrupted' || r.state === 'cancelled').map((r) => r.run_id)
|
|
207
|
+
const leave = stopped.length ? ` ${stopped.join(', ')} did not end by ${stopped.length === 1 ? 'its' : 'their'} own work (stopped by the user, cancelled or cut off by a Harness restart, see ${stopped.length === 1 ? 'its' : 'each'} hint): send ${stopped.length === 1 ? 'it' : 'them'} nothing more on your own and leave ${stopped.length === 1 ? 'it' : 'them'} out of the next wait.` : ''
|
|
203
208
|
const next = ids.length
|
|
204
209
|
? `Then call dsh_wait again with run_ids: the ones still running (${ids.join(', ')}) plus the run_id of every fix you sent, so whichever ends next comes back first. Do not wait for one run on its own while others are going.`
|
|
205
210
|
: 'None of these runs is still going.'
|
|
206
211
|
return {
|
|
207
212
|
ended, still_running: running,
|
|
208
|
-
hint: `${ended.length} of the runs ${ended.length === 1 ? 'has' : 'have'} ended or stopped to ask (ended; each has its own hint). Deal with ${ended.length === 1 ? 'it' : 'them'} now: review against what you asked, and send any fixes with dsh_send to the same session_id right away, or answer a question
|
|
213
|
+
hint: `${ended.length} of the runs ${ended.length === 1 ? 'has' : 'have'} ended or stopped to ask (ended; each has its own hint). Deal with ${ended.length === 1 ? 'it' : 'them'} now: review against what you asked, and send any fixes with dsh_send to the same session_id right away, or answer a question.${leave} ${next}`,
|
|
209
214
|
}
|
|
210
215
|
}
|
|
211
216
|
|
|
@@ -364,7 +369,7 @@ const TOOLS = [
|
|
|
364
369
|
{
|
|
365
370
|
name: 'dsh_answer',
|
|
366
371
|
annotations: annotations('Answer question', hints(false, false, false)),
|
|
367
|
-
description: `Answer the questions a waiting run asked (needs_input
|
|
372
|
+
description: `Answer the questions a waiting run asked (needs_input in dsh_wait or dsh_status). ${core.ASKED} Per question: choose (option numbers or labels), text (your own answer, complete on its own), or skip. It reaches Harness once every question has an answer (submitted: true; remaining lists the rest); then wait again. If the user already answered in Harness, it says there is no open question.`,
|
|
368
373
|
inputSchema: {
|
|
369
374
|
type: 'object', required: ['answers'], properties: {
|
|
370
375
|
run_id: str('Run id that is waiting (needs_input: answer)'),
|
|
@@ -374,7 +379,7 @@ const TOOLS = [
|
|
|
374
379
|
type: 'object', properties: {
|
|
375
380
|
id: str('Question id from question.questions[].id; may be left out when there is one question'),
|
|
376
381
|
choose: { type: 'array', items: { type: ['integer', 'string'] }, description: 'Option numbers (1 = first) or labels; one for a single-choice question' },
|
|
377
|
-
text: str('
|
|
382
|
+
text: str('Your own answer in words'),
|
|
378
383
|
skip: { type: 'boolean', description: 'Skip this question' },
|
|
379
384
|
},
|
|
380
385
|
},
|
|
@@ -384,6 +389,8 @@ const TOOLS = [
|
|
|
384
389
|
},
|
|
385
390
|
run: async (a) => {
|
|
386
391
|
const st = await core.api.answer(a)
|
|
392
|
+
// The second look at an option chosen for the user: nothing was sent, its hint says what next.
|
|
393
|
+
if (st.check) return st
|
|
387
394
|
if (!a.run_id) return { ...st, hint: `${st.reason ? 'Tell the user what you chose and this reason. ' : ''}Then call dsh_wait again as before (the same run_id or session_id), with the same until and the last cursor.` }
|
|
388
395
|
return {
|
|
389
396
|
...st,
|