dsh-baton-mcp 0.6.16 → 0.6.18

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 CHANGED
@@ -211,7 +211,7 @@ Working alone, Astra rated its own work 23/23; the independent check found 17/23
211
211
  - **Claude Code** waits for a run in the background (the `wait_command` that `dsh_send` returns) and is woken once, when the run ends.
212
212
  - **Codex** waits inside `dsh_wait`. The plugin sets Codex's tool timeout for dsh-baton to an hour (`tool_timeout_sec = 3600`), so one call waits up to 59 minutes: a run that ends within the hour costs one model request to wait for, however long it takes, and the result comes back as an ordinary tool result in the chat. A longer run returns `timed_out` with just the state after 59 minutes, and Codex calls again without summarising. Pressing Stop ends the wait at once. Codex gets no `wait_command`: its terminal cannot wake it, so it would poll. A conversation without that setting waits 270 s per call. Measured in the Codex desktop app: a 28-minute run took one `dsh_wait` call; a 62-minute run took two, the first returning `timed_out` after 59 minutes and the second getting the result 3 minutes later, with no `dsh_status` calls in between.
213
213
  - **Several runs at once.** When a task is split across sessions (say docs, front end and back end, each in its own worktree), the client sends them all, then waits for them together: Claude Code runs one `wait_command` per run in the background, and Codex calls `dsh_wait` with `run_ids`. That call returns as soon as any of the runs ends or stops to ask a person, with every run that has (`ended`) and the ones still going (`still_running`); the client reviews those, sends fixes right away, and waits again with the rest plus the fixes. Measured on a three-part task: waiting for one run at a time, the back end that ended first was read 2 min 53 s late; waiting with `run_ids`, each result was read within a second of its run ending.
214
- - **Sessions with a Harness goal.** A goal (a message starting with `/goal` sets one) makes Harness start the next round by itself as soon as a turn ends. A run sent to such a session is waited for until the goal stops, not just its first round, so "hand this to Harness" brings back the finished work; sessions without a goal are waited for as before. When the user asks for progress reports ("report every 10 minutes"), the client passes `until` `turn`: it then reports at the end of a round once 10 minutes (`every_minutes`) have passed since the last report, with every round since. To follow a session without sending anything, the client calls `dsh_wait` with `session_id` (Claude Code runs the `follow_command` in the background instead). Each report carries every round since the last one (the latest round's closing reply (up to 1500 characters), each earlier round as a one-line digest with its tools; any round in full through `dsh_read_session`), the files changed in the folder since the last report (since the run began, for the first), and the goal's state (phase, rounds started of the most allowed, whether Harness goes on with it), plus a `cursor` that the next call passes back, so switching between the two modes neither repeats nor misses a round. Both return at once when Harness asks a question (answer it with `dsh_answer` and `session_id`) or waits for an approval, when the goal is complete, paused, blocked or cleared, or when Harness will not go on with it by itself (for example after a Harness restart, until you press Continue). In Codex one call follows a goal for at most 15 minutes and Codex then calls again, so a message you type reaches it within that time; such an in-between return carries only the goal's state and how many rounds wait, not their texts.
214
+ - **Sessions with a Harness goal.** A goal (a message starting with `/goal` sets one) makes Harness start the next round by itself as soon as a turn ends. A `dsh_send` message `/goal <objective>` sets the goal through Harness's own goal service, as typing it in Harness does, and the objective goes in as the run's message; `/goal edit <objective>` replaces the objective of the goal there is. `/goal pause`, `resume` and `clear` work only in the Harness window; sent through dsh-baton they are refused, and so is a new `/goal` for a session whose goal is still active. A run sent to such a session is waited for until the goal stops, not just its first round, so "hand this to Harness" brings back the finished work; sessions without a goal are waited for as before. When the user asks for progress reports ("report every 10 minutes"), the client passes `until` `turn`: it then reports at the end of a round once 10 minutes (`every_minutes`) have passed since the last report, with every round since. To follow a session without sending anything, the client calls `dsh_wait` with `session_id` (Claude Code runs the `follow_command` in the background instead). Each report carries every round since the last one (the latest round's closing reply (up to 1500 characters), each earlier round as a one-line digest with its tools; any round in full through `dsh_read_session`), the files changed in the folder since the last report (since the run began, for the first), and the goal's state (phase, rounds started of the most allowed, whether Harness goes on with it), plus a `cursor` that the next call passes back, so switching between the two modes neither repeats nor misses a round. Both return at once when Harness asks a question (answer it with `dsh_answer` and `session_id`) or waits for an approval, when the goal is complete, paused, blocked or cleared, or when Harness will not go on with it by itself (for example after a Harness restart, until you press Continue). In Codex one call follows a goal for at most 15 minutes and Codex then calls again, so a message you type reaches it within that time; such an in-between return carries only the goal's state and how many rounds wait, not their texts.
215
215
  - **Changing the request while it waits.** In Codex, send the change with **Steer**: Codex stops waiting at once, steers it into the same Harness session (`dsh_send` with `mode` `steer`) and waits on the new run; Harness does both in the same turn. Sent with **Queue**, Codex sees it only when the run ends; you can also press Stop first and then send it. In Claude Code, just send it: it waits in the background, so it steers the change in right away. A steered run ends together with the original and they share one result; a queued run comes back on its own. Runs working in the same folder at the same time are named in each other's results, so neither removes the other's files.
216
216
 
217
217
  </details>
@@ -250,9 +250,9 @@ The server's MCP instructions are a single sentence; how to hand over, wait and
250
250
  | `dsh_list_sessions` | Sessions newest first, with title, folder, running state and `model` (what its next request uses); filter by folder or text. Archived sessions are left out |
251
251
  | `dsh_list_models` | The models Harness can run (provider, id, name, reasoning efforts) and its default model |
252
252
  | `dsh_read_session` | Recent prompts and replies of one session (with tool names); `archived: true` for an archived session |
253
- | `dsh_send` | Send a message: `session_id` continues that session; otherwise a new one starts in `cwd` or `workspace_id`, or, with neither, in the folder the conversation works in (a `cwd` that is not a workspace yet is registered first; a `cwd` outside the conversation's folder is allowed and noted in `folder_note`). A `cwd` inside the conversation's folder joins that folder's workspace instead of getting one of its own: the session opens in the conversation's folder and the message names the subfolder (`work_folder`), where `checks` run. Folders a client makes per conversation share one workspace each: Codex chats without a project (Codex chats), Claude scratch folders (Claude scratch), Codex worktrees (Codex worktrees) and a project's Claude worktrees (Claude worktrees). A folder that is a workspace already, or a Git worktree, keeps its own. `checks`: test commands dsh-baton runs itself when the run ends (see [How a hand-over is checked](#how-a-hand-over-is-checked)). Returns a `run_id` at once. In Harness the message is marked "Sent by Claude / ChatGPT from another chat". An archived session is refused: unarchive it in Harness, or start a new session. To a busy session, `mode` `followup` queues the message after the current turn and `steer` adds it to the running turn; left out, it does what Harness's own setting says (Settings → sending while busy: queue or steer), and `followup` when that cannot be read. `mode_source` says which applied. `model` only when the user names one ("DeepSeek-V4 Pro", "v4-pro"; `reasoning_effort` likewise): it is matched against Harness's own model list, ignoring case, spaces, hyphens and a leading DeepSeek, so a model Harness adds later (V4.1 Pro) works as soon as Harness lists it; a name that matches nothing or several fails the send, before anything is created, with the list (`provider/model` picks one). It is set on that session before the message goes in, and Harness's default model is put back as it was (Harness saves a session's pick as the default too). Left out, a continued session keeps its own model and a new one uses the hand-over default from the plugin page, else Harness's default. The reply says which in `model` and `model_source` (`requested`, `handover_default`, `default` or `session`), and `model_note` says when a hand-over default was skipped or Harness's default changed since the last new hand-over. `team` (Harness 0.2.2-rc.2 or later): `true` turns Agent Teams on for the session before the message goes in, `false` turns them off; refused, with nothing sent, on an older Harness or on a sub-agent's session |
253
+ | `dsh_send` | Send a message: `session_id` continues that session. Without it, a task for a folder where this conversation already has an idle session continues that session, so Harness keeps the earlier context (`continued_session` says so; `new_session` `true` starts a fresh one); a busy session is never reused, so parts sent in parallel get a session each. Otherwise a new one starts in `cwd` or `workspace_id`, or, with neither, in the folder the conversation works in (a `cwd` that is not a workspace yet is registered first; a `cwd` outside the conversation's folder is allowed and noted in `folder_note`). A `cwd` inside the conversation's folder joins that folder's workspace instead of getting one of its own: the session opens in the conversation's folder and the message names the subfolder (`work_folder`), where `checks` run. Folders a client makes per conversation share one workspace each: Codex chats without a project (Codex chats), Claude scratch folders (Claude scratch), Codex worktrees (Codex worktrees) and a project's Claude worktrees (Claude worktrees). A folder that is a workspace already, or a Git worktree, keeps its own. `checks`: test commands dsh-baton runs itself when the run ends (see [How a hand-over is checked](#how-a-hand-over-is-checked)). Returns a `run_id` at once. In Harness the message is marked "Sent by Claude / ChatGPT from another chat". An archived session is refused: unarchive it in Harness, or start a new session. To a busy session, `mode` `followup` queues the message after the current turn and `steer` adds it to the running turn; left out, it does what Harness's own setting says (Settings → sending while busy: queue or steer), and `followup` when that cannot be read. `mode_source` says which applied. `model` only when the user names one ("DeepSeek-V4 Pro", "v4-pro"; `reasoning_effort` likewise): it is matched against Harness's own model list, ignoring case, spaces, hyphens and a leading DeepSeek, so a model Harness adds later (V4.1 Pro) works as soon as Harness lists it; a name that matches nothing or several fails the send, before anything is created, with the list (`provider/model` picks one). It is set on that session before the message goes in, and Harness's default model is put back as it was (Harness saves a session's pick as the default too). Left out, a continued session keeps its own model and a new one uses the hand-over default from the plugin page, else Harness's default. The reply says which in `model` and `model_source` (`requested`, `handover_default`, `default` or `session`), and `model_note` says when a hand-over default was skipped or Harness's default changed since the last new hand-over. `team` (Harness 0.2.2-rc.2 or later): `true` turns Agent Teams on for the session before the message goes in, `false` turns them off; refused, with nothing sent, on an older Harness or on a sub-agent's session |
254
254
  | `dsh_status` | Run progress: state, recent text and tool calls, final reply; `waiting_on` when the turn is over but sub-agents or jobs still run; `human_interjections` when someone typed in the Harness UI mid-run; state `interrupted` for a run cut short by a Harness restart; `model` the run was sent with. With `session_id` instead of `run_id`: what the session is doing, its Harness goal and its last turn's reply |
255
- | `dsh_wait` | Wait for the run to end; a finished run carries `evidence` (files changed, check results) when the message was sent with `checks` (or until it stops to ask a person, see `dsh_answer`): up to 3540 s per call for Codex (its tool timeout for dsh-baton less 60 s; 270 s when that is not set), 50 s for other clients. Still going: returns `timed_out` with just the state; call it again. Clients that can wait in the background use `dsh_send`'s `wait_command` instead. `dsh_status` is a one-off look, not a way to wait. A run in a session with a Harness goal is waited for until the goal stops (`until` `turn` and `every_minutes` for progress reports). With `session_id` instead of `run_id` it follows the session's Harness goal without sending anything (`until`, `cursor`, `every_minutes`; see How each client waits). With `run_ids` it waits for several runs and returns as soon as any ends or asks (`ended`, `still_running`) |
255
+ | `dsh_wait` | Wait for the run to end; a finished run carries `evidence` (files changed, check results) when the message was sent with `checks` (or until it stops to ask a person, see `dsh_answer`): up to 3540 s per call for Codex (its tool timeout for dsh-baton less 60 s; 270 s when that is not set), 50 s for other clients. Still going: returns `timed_out` with just the state; call it again. Clients that can wait in the background use `dsh_send`'s `wait_command` instead; for a run a background `wait_command` already waits for, `dsh_wait` returns at once (`waiting_in_background`) rather than waiting a second time. `dsh_status` is a one-off look, not a way to wait. A run in a session with a Harness goal is waited for until the goal stops (`until` `turn` and `every_minutes` for progress reports). With `session_id` instead of `run_id` it follows the session's Harness goal without sending anything (`until`, `cursor`, `every_minutes`; see How each client waits). With `run_ids` it waits for several runs and returns as soon as any ends or asks (`ended`, `still_running`) |
256
256
  | `dsh_answer` | Send your answer to the questions a run stopped to ask (Harness's ask_user_question): per question, an option number or label, free text, or skip; on a single choice, free text replaces the option. `dsh_wait` and `wait_command` return as soon as a run asks, with the questions (`needs_input`, `question`; the option Harness's model would pick is in `harness_suggested`); the main agent asks you and sends your answer. You can also answer in the Harness window: whoever answers first wins |
257
257
  | `dsh_session_activity` | Codex: through `dsh_call`. What a session is doing now: running turn, sub-agents (any depth), background jobs; `archived: true` for an archived session |
258
258
  | `dsh_update_queued` | Codex: through `dsh_call`. Change a message still waiting in the queue of a busy session, by its `run_id`: `edit` its text, `remove` it, or `steer` it into the running turn now. Once it has reached the conversation it can no longer be changed |
package/README.zh-CN.md CHANGED
@@ -211,7 +211,7 @@ Codex 占 ChatGPT Plus 5 小时额度的比例,以及主 Agent 自己的花费
211
211
  - **Claude Code** 在后台等待任务(`dsh_send` 返回的 `wait_command`),任务结束时只被唤醒一次。
212
212
  - **Codex** 在 `dsh_wait` 里等待。插件把 Codex 对 dsh-baton 的工具超时设为一小时(`tool_timeout_sec = 3600`),所以一次调用最多能等 59 分钟:一小时以内跑完的任务,不管跑多久,等待只花一次模型请求,结果作为普通的工具结果回到对话里。超过 59 分钟会返回 `timed_out`,只带状态,Codex 直接再调用一次,不会去总结进度。等待中按停止会立刻停下。Codex 不会收到 `wait_command`:它的终端无法在命令结束时唤醒它,只能轮询。没有这项设置的对话每次最多等 270 秒。实测(Codex 桌面端):28 分钟的任务只调了 1 次 `dsh_wait`;62 分钟的任务调了 2 次,第一次等满 59 分钟返回 `timed_out`,接着再等 3 分钟拿到结果;期间没有调用 `dsh_status`。
213
213
  - **同时等多个任务**。一个任务拆给几个会话做时(比如接口文档、前端、后端,各在自己的 worktree 里),客户端先全部发出去,再一起等:Claude Code 给每个任务在后台各开一个 `wait_command`,Codex 调一次带 `run_ids` 的 `dsh_wait`。只要其中任何一个做完或停下来问人,这次调用就立刻返回,带上所有已经做完的(`ended`)和还在跑的(`still_running`);客户端检查这些结果、马上发返修,再带着剩下的和返修的一起接着等。实测一个分三部分的任务:一次只等一个时,最先做完的后端晚了 2 分 53 秒才被看到;用 `run_ids` 一起等时,每个结果都在做完 1 秒内拿到。
214
- - **带 Harness 目标的会话**。有了目标(以 `/goal` 开头的消息会设置目标),Harness 在一个回合结束后会自己开始下一轮。发给这种会话的任务会一直等到目标停下,而不只是第一轮,所以一句“交给 Harness”就能拿回做完的结果;没有目标的会话照旧等待。用户要求汇报进度时(“每 10 分钟汇报一次”),客户端传 `until` 为 `turn`:距上次报告满 10 分钟(`every_minutes`)后的第一个回合结束时报告,带上这期间的每一轮。想不发消息只跟进某个会话,客户端用 `session_id` 调 `dsh_wait`(Claude Code 则在后台运行 `follow_command`)。每份报告带着自上次报告以来的每一轮(最新一轮的结尾回复(最多 1500 字),之前每一轮一行摘要和用过的工具;任何一轮的全文可以用 `dsh_read_session` 看)、文件夹里自上次报告以来改动的文件(第一份从任务开始算起)、目标状态(阶段、已开始的轮数和上限、Harness 会不会自己接着做),以及下次调用要传回的 `cursor`,所以两种方式之间切换既不会重复也不会漏掉哪一轮。两种方式在这些情况下都会立刻返回:Harness 提问(用 `dsh_answer` 加 `session_id` 回答)或等待审批;目标完成、暂停、受阻或被清除;Harness 不会自己接着做(比如 Harness 重启后,要等你按“继续”)。在 Codex 里,一次调用最多跟进 15 分钟,然后 Codex 再接着调用,所以你打的新消息最晚 15 分钟内就能被看到;这种中途返回只带目标状态和还有几轮没报告,不带各轮全文。
214
+ - **带 Harness 目标的会话**。有了目标(以 `/goal` 开头的消息会设置目标),Harness 在一个回合结束后会自己开始下一轮。通过 `dsh_send` 发 `/goal 目标内容`,会用 Harness 自己的目标服务设置目标,和在 Harness 里直接输入一样,目标内容作为这次任务的消息发过去;`/goal edit 新内容` 改掉现有目标的内容。`/goal pause`、`resume`、`clear` 只能在 Harness 窗口里用,通过 dsh-baton 发会被拒绝;会话里已有未完成的目标时再发新的 `/goal` 也会被拒绝。发给这种会话的任务会一直等到目标停下,而不只是第一轮,所以一句“交给 Harness”就能拿回做完的结果;没有目标的会话照旧等待。用户要求汇报进度时(“每 10 分钟汇报一次”),客户端传 `until` 为 `turn`:距上次报告满 10 分钟(`every_minutes`)后的第一个回合结束时报告,带上这期间的每一轮。想不发消息只跟进某个会话,客户端用 `session_id` 调 `dsh_wait`(Claude Code 则在后台运行 `follow_command`)。每份报告带着自上次报告以来的每一轮(最新一轮的结尾回复(最多 1500 字),之前每一轮一行摘要和用过的工具;任何一轮的全文可以用 `dsh_read_session` 看)、文件夹里自上次报告以来改动的文件(第一份从任务开始算起)、目标状态(阶段、已开始的轮数和上限、Harness 会不会自己接着做),以及下次调用要传回的 `cursor`,所以两种方式之间切换既不会重复也不会漏掉哪一轮。两种方式在这些情况下都会立刻返回:Harness 提问(用 `dsh_answer` 加 `session_id` 回答)或等待审批;目标完成、暂停、受阻或被清除;Harness 不会自己接着做(比如 Harness 重启后,要等你按“继续”)。在 Codex 里,一次调用最多跟进 15 分钟,然后 Codex 再接着调用,所以你打的新消息最晚 15 分钟内就能被看到;这种中途返回只带目标状态和还有几轮没报告,不带各轮全文。
215
215
  - **等待中想改需求**。Codex:在输入框里用**引导**发出新要求,Codex 会立刻停止等待,用 `dsh_send`(`mode` 为 `steer`)把它插进同一个 Harness 对话,改等新的任务,Harness 在同一轮里把新要求一起做完;用**排队**发的话,要等这次任务做完才会被看到。也可以先按停止再发。Claude Code:随时发就行,它在后台等待,马上就能把新要求插队转给 Harness。插队的任务和原任务同时结束,共用一份结果;排队的任务单独返回。同一个文件夹里同时跑多个任务时,结果里会标出其他任务,不会删掉别人的文件。
216
216
 
217
217
  </details>
@@ -250,9 +250,9 @@ Codex 占 ChatGPT Plus 5 小时额度的比例,以及主 Agent 自己的花费
250
250
  | `dsh_list_sessions` | 列出对话(最新在前),带标题、目录、是否在跑和 `model`(下一次请求用的模型);可按目录或关键字过滤。已归档的对话不会列出 |
251
251
  | `dsh_list_models` | 列出 Harness 能用的模型(provider、id、名称、推理强度)和它的默认模型 |
252
252
  | `dsh_read_session` | 读某个对话最近的消息和回复(含用到的工具名);已归档的对话会带 `archived: true` |
253
- | `dsh_send` | 发消息。带 `session_id` 续接那个对话;否则新开对话,建在 `cwd` 或 `workspace_id` 指定的位置,都不带时建在当前对话所在的文件夹(`cwd` 还不是工作区时会先登记;指定的 `cwd` 在当前对话文件夹之外也可以,结果里的 `folder_note` 会提醒)。`cwd` 在当前对话文件夹里面时,不再单独建工作区,而是进当前对话文件夹的工作区:对话开在那个文件夹,消息里写明要在哪个子文件夹工作(`work_folder`),`checks` 也在子文件夹里跑。客户端给每个对话单独建的文件夹各自共用一个工作区:Codex 没选项目的对话(Codex chats)、Claude 的 scratch 文件夹(Claude scratch)、Codex 的 worktree(Codex worktrees)、同一项目的 Claude worktree(Claude worktrees)。本来就是工作区的文件夹,或者 Git worktree,仍用它自己的工作区。`checks`:运行结束后 dsh-baton 自己跑的测试命令(见[转交之后怎么验收](#转交之后怎么验收))。立即返回 `run_id`。Harness 里这条消息会标注「由 Claude / ChatGPT 从另一个聊天发送」。已归档的对话会被拒绝:先在 Harness 里取消归档,或新开对话。对话正忙时,`mode` 为 `followup` 会排在当前回合之后,`steer` 会插进正在跑的回合;不传时跟随 Harness 自己的设置(设置 → 繁忙时的发送行为:排队发送或插话发送),读不到设置时按 `followup`。返回里的 `mode_source` 说明用的是哪种。`model` 只在用户点名模型时传(如“DeepSeek-V4 Pro”“v4-pro”;`reasoning_effort` 同理):按 Harness 自己的模型列表匹配,不分大小写,忽略空格、连字符和开头的 DeepSeek,所以 Harness 以后上线的模型(如 V4.1 Pro)一出现在列表里就能用;匹配不到或匹配到多个时,发送直接失败、什么都不创建,并列出可用模型(用 `provider/model` 指定其一)。模型在消息发出前设到该对话上,Harness 的默认模型会恢复原样(Harness 会把对话里选的模型同时存成默认)。不传时,续接的对话沿用它自己的模型,新对话用插件页的转交默认模型,没设就用 Harness 默认模型。返回值的 `model` 和 `model_source`(`requested`、`handover_default`、`default` 或 `session`)写明用的是哪个;转交默认模型用不上,或 Harness 的默认模型和上一次新开转交时不一样时,`model_note` 会说明。`team`(需要 Harness 0.2.2-rc.2 及以上):`true` 在消息发出前为该对话打开智能体团队协作,`false` 关闭;Harness 版本太旧或传的是子智能体的对话时,直接拒绝、什么都不发 |
253
+ | `dsh_send` | 发消息。带 `session_id` 续接那个对话。不带时,如果当前对话在这个文件夹里已经有一个空闲的对话,就续接它,Harness 保留之前的上下文(结果里的 `continued_session` 会说明;`new_session` 为 `true` 时新开一个);正忙的对话不会被续接,所以并行发出的几部分仍各开一个对话。其余情况新开对话,建在 `cwd` 或 `workspace_id` 指定的位置,都不带时建在当前对话所在的文件夹(`cwd` 还不是工作区时会先登记;指定的 `cwd` 在当前对话文件夹之外也可以,结果里的 `folder_note` 会提醒)。`cwd` 在当前对话文件夹里面时,不再单独建工作区,而是进当前对话文件夹的工作区:对话开在那个文件夹,消息里写明要在哪个子文件夹工作(`work_folder`),`checks` 也在子文件夹里跑。客户端给每个对话单独建的文件夹各自共用一个工作区:Codex 没选项目的对话(Codex chats)、Claude 的 scratch 文件夹(Claude scratch)、Codex 的 worktree(Codex worktrees)、同一项目的 Claude worktree(Claude worktrees)。本来就是工作区的文件夹,或者 Git worktree,仍用它自己的工作区。`checks`:运行结束后 dsh-baton 自己跑的测试命令(见[转交之后怎么验收](#转交之后怎么验收))。立即返回 `run_id`。Harness 里这条消息会标注「由 Claude / ChatGPT 从另一个聊天发送」。已归档的对话会被拒绝:先在 Harness 里取消归档,或新开对话。对话正忙时,`mode` 为 `followup` 会排在当前回合之后,`steer` 会插进正在跑的回合;不传时跟随 Harness 自己的设置(设置 → 繁忙时的发送行为:排队发送或插话发送),读不到设置时按 `followup`。返回里的 `mode_source` 说明用的是哪种。`model` 只在用户点名模型时传(如“DeepSeek-V4 Pro”“v4-pro”;`reasoning_effort` 同理):按 Harness 自己的模型列表匹配,不分大小写,忽略空格、连字符和开头的 DeepSeek,所以 Harness 以后上线的模型(如 V4.1 Pro)一出现在列表里就能用;匹配不到或匹配到多个时,发送直接失败、什么都不创建,并列出可用模型(用 `provider/model` 指定其一)。模型在消息发出前设到该对话上,Harness 的默认模型会恢复原样(Harness 会把对话里选的模型同时存成默认)。不传时,续接的对话沿用它自己的模型,新对话用插件页的转交默认模型,没设就用 Harness 默认模型。返回值的 `model` 和 `model_source`(`requested`、`handover_default`、`default` 或 `session`)写明用的是哪个;转交默认模型用不上,或 Harness 的默认模型和上一次新开转交时不一样时,`model_note` 会说明。`team`(需要 Harness 0.2.2-rc.2 及以上):`true` 在消息发出前为该对话打开智能体团队协作,`false` 关闭;Harness 版本太旧或传的是子智能体的对话时,直接拒绝、什么都不发 |
254
254
  | `dsh_status` | 查看运行进度:状态、最近的文字和工具调用、最终回复;回合结束但子智能体/后台任务还在跑时给出 `waiting_on`;中途有人在 Harness 界面里发消息时给出 `human_interjections`;被 Harness 重启打断的任务状态为 `interrupted`;以及这次运行发送时用的 `model`。用 `session_id` 代替 `run_id` 时:会话正在做什么、它的 Harness 目标,以及上一回合的回复 |
255
- | `dsh_wait` | 等运行结束;发消息时带了 `checks` 的,结束后会附上 `evidence`(改了哪些文件、测试结果)(或者等到它停下来问人,见 `dsh_answer`):Codex 每次最多等 3540 秒(它对 dsh-baton 的工具超时减 60 秒;没设时 270 秒),其他客户端 50 秒。没做完会带 `timed_out`,只返回状态,再调用一次即可。能在后台等待的客户端改用 `dsh_send` 返回的 `wait_command`。`dsh_status` 只用来看一眼,不用来等待。发到带 Harness 目标的会话的任务会一直等到目标停下(要汇报进度时用 `until` 为 `turn` 和 `every_minutes`)。用 `session_id` 代替 `run_id` 时,不发任何消息,跟进这个会话的 Harness 目标(`until`、`cursor`、`every_minutes`;见“各客户端怎么等待”)。用 `run_ids` 时同时等多个任务,任何一个做完或提问就返回(`ended`、`still_running`) |
255
+ | `dsh_wait` | 等运行结束;发消息时带了 `checks` 的,结束后会附上 `evidence`(改了哪些文件、测试结果)(或者等到它停下来问人,见 `dsh_answer`):Codex 每次最多等 3540 秒(它对 dsh-baton 的工具超时减 60 秒;没设时 270 秒),其他客户端 50 秒。没做完会带 `timed_out`,只返回状态,再调用一次即可。能在后台等待的客户端改用 `dsh_send` 返回的 `wait_command`;某个任务已经有后台 `wait_command` 在等时,`dsh_wait` 会立即返回(`waiting_in_background`),不再重复等待。`dsh_status` 只用来看一眼,不用来等待。发到带 Harness 目标的会话的任务会一直等到目标停下(要汇报进度时用 `until` 为 `turn` 和 `every_minutes`)。用 `session_id` 代替 `run_id` 时,不发任何消息,跟进这个会话的 Harness 目标(`until`、`cursor`、`every_minutes`;见“各客户端怎么等待”)。用 `run_ids` 时同时等多个任务,任何一个做完或提问就返回(`ended`、`still_running`) |
256
256
  | `dsh_answer` | 把你对运行中途提问的回答发回去(Harness 的 ask_user_question):每道题可以填选项编号或选项文字、自由填写,或者跳过;单选题填了文字就以文字为准。运行一提问,`dsh_wait` 和 `wait_command` 就立刻返回,带上题目(`needs_input`、`question`;Harness 模型推荐的选项在 `harness_suggested`),由主 Agent 问你并把你的回答发回去。你也可以直接在 Harness 窗口里回答,谁先答就算谁的 |
257
257
  | `dsh_session_activity` | Codex 里经 `dsh_call` 调用。对话此刻在做什么:正在跑的回合、子智能体(任意层级)、后台任务;已归档的对话会带 `archived: true` |
258
258
  | `dsh_update_queued` | Codex 里经 `dsh_call` 调用。按 `run_id` 修改还在忙碌对话队列里等待的消息:`edit` 改文字,`remove` 撤回,`steer` 立刻插进正在跑的回合。消息一旦进入对话就改不了了 |
package/host/lib/index.js CHANGED
@@ -65,8 +65,11 @@ function normalizePath(p) {
65
65
  // one more in the sidebar for each subfolder or throw-away folder. Instead it joins:
66
66
  // - the conversation's own folder (base), when the target is inside it: a Claude Code chat in
67
67
  // Coding handing over Coding/app joins the Coding workspace;
68
+ // - for a target outside it, the nearest workspace around the target, else the conversation's
69
+ // own folder: a chat in Coding handing over a folder on another disk joins the Coding workspace;
68
70
  // - for folders clients make per conversation, one shared folder: Codex chats without a project
69
- // (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces/…), Claude
71
+ // (Documents/Codex/<date>/<chat>), Claude scratch folders (…/scratch-workspaces/…, Claude
72
+ // Code's <tmp>/claude-<uid>/…/scratchpad), Antigravity's scratch and brain folders, Claude
70
73
  // worktrees (<project>/.claude/worktrees/<name>, joined to the project) and Codex worktrees
71
74
  // (~/.codex/worktrees/…).
72
75
  // The session then starts in that folder and the message names the target folder.
@@ -86,8 +89,16 @@ function sharedFolder(dir) {
86
89
  if (same(at, 'worktrees') && i >= 2 && same(parts[i - 1], '.claude')) return { path: upto(i + 1), title: 'Claude worktrees' }
87
90
  if (same(at, 'worktrees') && same(parts[i - 1], '.codex')) return { path: upto(i + 1), title: 'Codex worktrees' }
88
91
  if (same(at, 'scratch-workspaces')) return { path: upto(i + 1), title: 'Claude scratch' }
92
+ // Antigravity: chats outside a project work in <data>/scratch, artifacts sit in <data>/brain/<id>.
93
+ if ((same(at, 'scratch') || same(at, 'brain')) && /^antigravity/i.test(parts[i - 1] ?? '') && same(parts[i - 2] ?? '', '.gemini')) return { path: upto(i + 1), title: 'Antigravity scratch' }
89
94
  if (same(at, 'Codex') && same(parts[i - 1], 'Documents') && DAY.test(parts[i + 1] ?? '')) return { path: upto(i + 1), title: 'Codex chats' }
90
95
  }
96
+ // Claude Code's per-conversation scratchpad: <tmp>/claude[-<uid>]/<project>/<session>/scratchpad;
97
+ // every conversation's goes to the claude[-<uid>] folder (2026-11-20: a paper review gave each
98
+ // reviewer its own scratchpad subfolder, five workspaces).
99
+ for (let s = parts.length - 1; s >= 3; s--) {
100
+ if (same(parts[s], 'scratchpad') && /^claude(-\d+)?$/i.test(parts[s - 3])) return { path: upto(s - 2), title: 'Claude scratch' }
101
+ }
91
102
  return null
92
103
  }
93
104
  // A Git worktree (its .git is a file pointing into another repository's worktrees): a checkout
@@ -98,16 +109,29 @@ function isLinkedWorktree(dir) {
98
109
  return text.startsWith('gitdir:') && /[\\/]worktrees[\\/]/.test(text)
99
110
  } catch { return false }
100
111
  }
101
- function sessionHome(target, base) {
112
+ // known: the folders that are workspaces already.
113
+ function sessionHome(target, base, known = []) {
102
114
  const usable = (dir) => dir && !same(dir, os.homedir()) && dir !== path.parse(dir).root && isDirectory(dir)
103
- if (base && !isLinkedWorktree(target)) {
104
- let b = normalizePath(base)
105
- const shared = sharedFolder(b)
106
- if (shared && isDirectory(shared.path)) b = shared.path
107
- if (usable(b) && isInside(target, b)) return { path: b, ...(shared && same(b, shared.path) && shared.title ? { title: shared.title } : {}) }
115
+ const linked = isLinkedWorktree(target)
116
+ let b
117
+ let baseShared = null
118
+ if (base && !linked) {
119
+ b = normalizePath(base)
120
+ baseShared = sharedFolder(b)
121
+ if (baseShared && isDirectory(baseShared.path)) b = baseShared.path
122
+ if (usable(b) && isInside(target, b)) return { path: b, ...(baseShared && same(b, baseShared.path) && baseShared.title ? { title: baseShared.title } : {}) }
108
123
  }
109
124
  const shared = sharedFolder(target)
110
125
  if (shared && usable(shared.path)) return shared
126
+ if (b) {
127
+ // A folder outside the conversation's folder (2026-11-20: a chat in Coding gave each reviewer
128
+ // a folder of its own on another disk, one workspace each): the nearest workspace around it,
129
+ // else the conversation's own folder. Not a chat's throw-away folder (a Codex chat without
130
+ // a project): a project handed over from there keeps a workspace of its own.
131
+ const around = known.filter((dir) => dir && usable(dir) && isInside(target, dir)).sort((x, y) => y.length - x.length)[0]
132
+ if (around) return { path: around }
133
+ if (b && !baseShared && usable(b)) return { path: b }
134
+ }
111
135
  return { path: target }
112
136
  }
113
137
 
@@ -1600,17 +1624,58 @@ export function apply(ctx) {
1600
1624
  const TEAMS_UNSUPPORTED = 'this DeepSeek Harness cannot turn Agent Teams on per session; that needs Harness 0.2.2-rc.2 or later: update Harness, or send without team'
1601
1625
  async function setTeam(sessionId, enabled) {
1602
1626
  if (typeof teamsService?.setEnabled !== 'function') throw new Error(TEAMS_UNSUPPORTED)
1603
- // The exact live Agent from Harness's registry, as its own UI lookup takes it: Team rejects
1604
- // any other object ("subagent tree access requires the exact live caller"). A session not
1605
- // loaded yet is loaded first.
1627
+ const agent = await liveAgent(sessionId)
1628
+ // A finished sub-agent's session is never loaded again: name the likely cause.
1629
+ if (!agent) throw new Error(`session ${sessionId} is not loaded in Harness; if it is a sub-agent's (teammate's) session, change Team mode on its root session instead`)
1630
+ await teamsService.setEnabled(agent, enabled)
1631
+ }
1632
+
1633
+ // The exact live Agent from Harness's registry, as its own UI lookup takes it: Team and goals
1634
+ // reject any other object ("subagent tree access requires the exact live caller"). A session
1635
+ // not loaded yet is loaded first. undefined when it cannot be loaded.
1636
+ async function liveAgent(sessionId) {
1606
1637
  let agent = agentsService?.get?.(sessionId)
1607
1638
  if (!agent && typeof controller.resolveAgent === 'function') {
1608
1639
  await controller.resolveAgent(sessionId)
1609
1640
  agent = agentsService?.get?.(sessionId)
1610
1641
  }
1611
- // A finished sub-agent's session is never loaded again: name the likely cause.
1612
- if (!agent) throw new Error(`session ${sessionId} is not loaded in Harness; if it is a sub-agent's (teammate's) session, change Team mode on its root session instead`)
1613
- await teamsService.setEnabled(agent, enabled)
1642
+ return agent
1643
+ }
1644
+
1645
+ // --- /goal ------------------------------------------------------------------------
1646
+ // Harness runs /goal as a composer command (commands.execute), not as text for the model:
1647
+ // sent as a prompt it set no goal (Windows rc.2 on 11-17, Mac rc.5 on 11-21). So a leading
1648
+ // "/goal <objective>" sets the goal through Harness's goals service, as the command does, and
1649
+ // the objective goes in as the run's message. The goal is set once Harness has taken that
1650
+ // message in, so its round driver sees a queued prompt and waits: the run's own turn comes
1651
+ // first, then Harness goes on with the goal's rounds by itself.
1652
+ const GOAL_UNSUPPORTED = 'this DeepSeek Harness cannot set a goal from a plugin (no goals service); type /goal in the Harness window, or update Harness'
1653
+ function goalCommand(message) {
1654
+ const m = /^\/goal(?:\s+([^]*))?$/i.exec(message.trim())
1655
+ if (!m) return null
1656
+ const rest = (m[1] ?? '').trim()
1657
+ const word = rest.toLowerCase()
1658
+ if (!rest || ['clear', 'pause', 'resume', 'edit'].includes(word)) return { kind: 'control', word: word || 'show' }
1659
+ if (/^edit\s/i.test(rest)) return { kind: 'edit', objective: rest.slice(4).trim() }
1660
+ return { kind: 'create', objective: rest }
1661
+ }
1662
+ const GOAL_NOTE = '(This message also set a Harness goal for this session, with the text above as its objective. When all of it is done and verified, mark the goal complete; if work remains, leave it active and Harness starts the next goal round after this turn.)'
1663
+
1664
+ async function setGoal(run, cmd, objective) {
1665
+ try {
1666
+ const agent = await liveAgent(run.sessionId)
1667
+ if (!agent) throw new Error(`session ${run.sessionId} is not loaded in Harness`)
1668
+ const current = goalsService.get(agent)
1669
+ const view = cmd.kind === 'edit' && current && current.phase !== 'complete'
1670
+ ? goalsService.edit(agent, { id: current.id, revision: current.revision }, { objective })
1671
+ : goalsService.create(agent, { objective })
1672
+ run.goalSet = { id: view.id, phase: view.phase, max_rounds: view.maxGoalRounds ?? null }
1673
+ pushEvent(run, { type: 'goal_set', goal_id: view.id, edited: cmd.kind === 'edit' && view.revision > 1 })
1674
+ } catch (error) {
1675
+ run.goalError = String(error?.message ?? error)
1676
+ pushEvent(run, { type: 'goal_failed', error: run.goalError })
1677
+ logError('set goal', error)
1678
+ }
1614
1679
  }
1615
1680
 
1616
1681
  async function send({ message, session_id, cwd, workspace_id, conversation_folder, mode: asked, sender, model, reasoning_effort, team }) {
@@ -1632,6 +1697,14 @@ export function apply(ctx) {
1632
1697
  throw new Error(`Session ${sessionId} is archived. Unarchive it in Harness, or start a new session with cwd or workspace_id.`)
1633
1698
  }
1634
1699
  if (!sessionId && !cwd && !workspace_id) throw new Error('A new session needs cwd or workspace_id. Pass session_id to continue an existing one.')
1700
+ const goalCmd = goalCommand(message)
1701
+ if (goalCmd?.kind === 'control') throw new Error(`Nothing was sent: dsh_send takes "/goal <objective>" or "/goal edit <objective>"; /goal ${goalCmd.word === 'show' ? '' : goalCmd.word} works only in the Harness window. dsh_status with session_id shows a session's goal.`)
1702
+ if (goalCmd && (typeof goalsService?.create !== 'function' || typeof agentsService?.get !== 'function')) throw new Error(`Nothing was sent: ${GOAL_UNSUPPORTED}`)
1703
+ if (goalCmd?.kind === 'create' && sessionId) {
1704
+ const current = await goalOf(sessionId)
1705
+ if (current && current.phase !== 'complete') throw new Error(`No message was sent: session ${sessionId} already has a goal (${current.phase}: ${current.objective}). Send "/goal edit <objective>" to replace its objective, or clear it in the Harness window first.`)
1706
+ }
1707
+ if (goalCmd) message = goalCmd.objective
1635
1708
  // A missing folder is not created: a mistyped path, or a project on a drive that is not
1636
1709
  // connected, would get an empty folder (under /Volumes, even). Checked before the registry,
1637
1710
  // which answers a bare ENOENT, or nothing at all for a folder registered while it was there.
@@ -1672,7 +1745,7 @@ export function apply(ctx) {
1672
1745
  const target = normalizePath(cwd)
1673
1746
  // A folder that is a workspace already (sessions from before 0.6.15) keeps it.
1674
1747
  const own = await registry.resolveByPath(target).catch(() => undefined)
1675
- const home = own ? { path: target } : sessionHome(target, conversation_folder)
1748
+ const home = own ? { path: target } : sessionHome(target, conversation_folder, registry.list().map((w) => w.path))
1676
1749
  workspace = await createWorkspace({ path: home.path, title: home.title, create_dir: false })
1677
1750
  if (!same(home.path, target)) {
1678
1751
  workFolder = target
@@ -1740,9 +1813,10 @@ export function apply(ctx) {
1740
1813
  // session after a restart) that took 2 min 35 s, and the client sat in dsh_send all along
1741
1814
  // (Mac, 2026-11-18). So the reply waits at most admitWaitMs() (10 s); Harness's answer still settles
1742
1815
  // the run when it comes (a refusal fails it, and dsh_wait says so).
1743
- const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: message }], mode }, signal())
1744
- .then(() => {
1816
+ const admitted = controller.prompt({ sessionId, requestId: run.requestId, content: [{ type: 'text', text: goalCmd ? `${message}\n\n${GOAL_NOTE}` : message }], mode }, signal())
1817
+ .then(async () => {
1745
1818
  run.admitted = true // in Harness's queue (or conversation) now
1819
+ if (goalCmd) await setGoal(run, goalCmd, message)
1746
1820
  if (drift) rememberDefault(drift.now)
1747
1821
  return true
1748
1822
  }, (error) => {
@@ -1763,6 +1837,7 @@ export function apply(ctx) {
1763
1837
  ...(pagePart.length ? { handover_default: pagePart } : {}),
1764
1838
  ...(modelNotes.length ? { model_note: modelNotes.join(' ') } : {}),
1765
1839
  ...(team != null ? { team } : {}),
1840
+ ...(goalCmd && answered ? (run.goalSet ? { goal_set: run.goalSet } : { goal_error: run.goalError ?? 'not set' }) : {}),
1766
1841
  ...(ahead.length ? { other_active_runs: ahead } : {}),
1767
1842
  ...(queuedBehind ? { queued_behind: true } : {}),
1768
1843
  ...(workspace ? { workspace } : {}),
package/host/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-baton-host",
3
- "version": "0.6.16",
3
+ "version": "0.6.18",
4
4
  "description": "Hand coding tasks from Claude Code, Codex or Antigravity to DeepSeek Harness: they run live in the Harness window and come back with the changed files and test results. 让 Claude Code、Codex 和 Antigravity 把编码任务交给 DeepSeek Harness:在 Harness 窗口里实时跑,做完带着改动文件和测试结果交回。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -24,7 +24,7 @@
24
24
  "docs"
25
25
  ],
26
26
  "dependencies": {
27
- "dsh-baton-mcp": "0.6.16"
27
+ "dsh-baton-mcp": "0.6.18"
28
28
  },
29
29
  "license": "MIT",
30
30
  "dsh": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-baton-mcp",
3
- "version": "0.6.16",
3
+ "version": "0.6.18",
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.16",
10
+ "version": "0.6.18",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "dsh-baton-mcp",
15
- "version": "0.6.16",
15
+ "version": "0.6.18",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  }
package/src/cli.mjs CHANGED
@@ -5,6 +5,7 @@ import path from 'node:path'
5
5
  import * as core from './core.mjs'
6
6
  import { setup, stableNodePath } from './setup.mjs'
7
7
  import { runHook, parseHookInput } from './codex-hook.mjs'
8
+ import { markWaiting } from './waiters.mjs'
8
9
 
9
10
  const USAGE = `Usage: dsh-baton <command> [args]
10
11
 
@@ -88,6 +89,8 @@ async function main() {
88
89
  case 'status':
89
90
  return print(await core.api.status(rest[0]?.startsWith('session') || flags.session ? { session_id: flags.session ?? rest[0] } : { run_id: rest[0] }))
90
91
  case 'wait': {
92
+ // So that dsh_wait in the same client knows this run is waited for already.
93
+ markWaiting(rest[0])
91
94
  const total_s = Number(flags.timeout) || 24 * 3600
92
95
  const waitStarted = Date.now()
93
96
  const st = await core.api.wait({ run_id: rest[0], timeout_s: total_s })
package/src/folder.mjs CHANGED
@@ -129,6 +129,8 @@ const norm = (p) => {
129
129
  const r = path.resolve(p.replace(/^~(?=$|[\\/])/, os.homedir()))
130
130
  return process.platform === 'win32' || process.platform === 'darwin' ? r.toLowerCase() : r
131
131
  }
132
+ // A folder as compared with another one (case-insensitive where the file system is).
133
+ export const folderId = (p) => norm(p)
132
134
  // True when folder is the conversation's folder or inside it.
133
135
  export function within(folder, conversation) {
134
136
  const r = path.relative(norm(conversation), norm(folder))
package/src/mcp.mjs CHANGED
@@ -6,8 +6,9 @@ import path from 'node:path'
6
6
  import * as core from './core.mjs'
7
7
  import { stableNodePath } from './setup.mjs'
8
8
  import { codexConfigPath, readCodexToolTimeout, codexTimeoutNoteFile, codexWaitSeconds, codexConfigReadAt, codexProcessStartedAtAsync } from './register.mjs'
9
- import { conversationFolder, within } from './folder.mjs'
9
+ import { conversationFolder, within, folderId } from './folder.mjs'
10
10
  import { threadOf, delivered } from './codex-hook.mjs'
11
+ import { waitingInBackground } from './waiters.mjs'
11
12
 
12
13
  const SERVER = { name: 'dsh-baton', version: core.VERSION }
13
14
  const PROTOCOLS = ['2025-06-18', '2025-03-26', '2024-11-05']
@@ -32,6 +33,8 @@ const listsHidden = () => ['claude', 'antigravity'].includes(core.senderOf(clien
32
33
  // Codex (no wake-on-exit), and not Antigravity on Windows: its terminal is sandboxed there and
33
34
  // may not open Harness's named pipe (EPERM), while this server, started outside it, can.
34
35
  const backgroundWaits = () => !isCodex() && !(process.platform === 'win32' && core.senderOf(clientName) === 'antigravity')
36
+ // Claude Code itself (not the Claude desktop chat, claude-ai, which has no shell).
37
+ const isClaudeCode = () => /^claude-code/i.test(String(clientName ?? ''))
35
38
  let codexTimeout = { mtime: null, value: null }
36
39
  function codexToolTimeout() {
37
40
  try {
@@ -117,6 +120,40 @@ const FOLLOW_COMMAND_HINT = ' Your client wakes you when a background command ex
117
120
  // wait returned (measured 2026-11-08: a result read 3 minutes late, its rework sent late).
118
121
  const PARALLEL_HINT = 'If you are sending several parts in parallel, send them all first, then wait for them together: one dsh_wait with run_ids set to all their run_ids, never one run after another.'
119
122
 
123
+ // Sessions this conversation sent to, so that a new task for the same folder continues the
124
+ // session it used there before, when that one is idle, rather than starting a session per task
125
+ // (2026-11-19: three tasks in one project, one after another, went to three new sessions).
126
+ // Kept per conversation: Codex and Antigravity run one server for several conversations and
127
+ // send the conversation's id with each call; Claude Code runs one server per conversation.
128
+ // Kept in memory only: after a server restart (an update) the next task starts one more session.
129
+ const AG_META = 'antigravity.google/'
130
+ const conversationKey = (meta) => threadOf(meta) ?? meta?.[`${AG_META}root_conversation_id`] ?? meta?.[`${AG_META}conversation_id`] ?? 'this'
131
+ const usedSessions = new Map()
132
+ const folderKey = (a) => (a.workspace_id ? `workspace:${a.workspace_id}` : a.cwd ? `folder:${folderId(a.cwd)}` : null)
133
+ function rememberSession(meta, sessionId, folder) {
134
+ if (!sessionId) return
135
+ const key = conversationKey(meta)
136
+ if (!usedSessions.has(key)) usedSessions.set(key, new Map())
137
+ const mine = usedSessions.get(key)
138
+ const known = mine.get(sessionId)
139
+ if (folder || known) mine.set(sessionId, { folder: folder ?? known.folder, at: Date.now() })
140
+ }
141
+ // The session this conversation last used for folder, if it is idle now: no turn, no run of
142
+ // ours, no question, no goal going on, not archived. A busy one is never taken, so parts sent
143
+ // in parallel still get a session each.
144
+ async function idleSessionFor(meta, folder) {
145
+ const mine = usedSessions.get(conversationKey(meta))
146
+ if (!mine || !folder) return null
147
+ const candidates = [...mine].filter(([, v]) => v.folder === folder).sort((x, y) => y[1].at - x[1].at)
148
+ for (const [sid] of candidates) {
149
+ const st = await core.api.status({ session_id: sid }).catch(() => null)
150
+ if (!st || st.archived) { mine.delete(sid); continue }
151
+ if (st.busy || st.turn_running || st.bridge_runs?.length || st.needs_input || st.goal?.phase === 'active') continue
152
+ return sid
153
+ }
154
+ return null
155
+ }
156
+
120
157
  // Wait in short chunks, reporting progress between them (clients that support it can
121
158
  // show it or reset their timer). An unfinished wait returns only the state, not the run's
122
159
  // recent events, so the client has nothing to summarise and simply waits again.
@@ -150,6 +187,22 @@ async function waitInChunks({ run_id }, progress, signal, meta) {
150
187
  }
151
188
  }
152
189
 
190
+ // Runs a background wait_command of this machine already waits for (waiters.mjs): dsh_wait says
191
+ // so at once instead of waiting a second time in the foreground. Only for clients that wait in
192
+ // the background, and only while none of the runs has ended or asks (then the ordinary wait
193
+ // returns it at once).
194
+ const BACKGROUND_WAIT_HINT = (n) => `A background wait_command already waits for ${n > 1 ? 'these runs' : 'this run'} and wakes you when ${n > 1 ? 'each' : 'it'} ends or stops to ask the user something, so dsh_wait did not wait. Do not call dsh_wait for ${n > 1 ? 'them' : 'it'}: go on with other work, or end your turn if there is none.`
195
+ const STOPPED = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'waiting'])
196
+ async function waitedInBackground(ids) {
197
+ if (!backgroundWaits() || !ids.length || !ids.every((id) => waitingInBackground(id))) return null
198
+ const states = await Promise.all(ids.map((id) => core.api.status({ run_id: id, tail: 1 }).catch(() => null)))
199
+ if (states.some((st) => !st || STOPPED.has(st.state) || st.needs_input)) return null
200
+ const hint = BACKGROUND_WAIT_HINT(ids.length)
201
+ return ids.length === 1
202
+ ? { run_id: ids[0], state: states[0].state, waiting_in_background: true, hint }
203
+ : { run_ids: ids, still_running: states.map((st, i) => ({ run_id: ids[i], state: st.state, session_id: st.session_id })), waiting_in_background: true, hint }
204
+ }
205
+
153
206
  // Several runs (dsh_wait run_ids): returns as soon as any of them ends or stops to ask a person,
154
207
  // with every one that has by then and the ones still running. Each round asks about all of them
155
208
  // together for a short chunk, so an ending is seen within MULTI_CHUNK_S. Every answer is kept:
@@ -298,8 +351,8 @@ const TOOLS = [
298
351
  {
299
352
  name: 'dsh_send',
300
353
  annotations: annotations('Send message', hints(false, false, false)),
301
- description: 'Hand a task to DeepSeek Harness, or continue a session: returns at once with a run_id and a hint saying how to wait for the reply; follow it. Call it directly, no need to list anything first. A new session starts in the folder this conversation works in, or in cwd or workspace_id (a new cwd is registered first); session_id continues that session. message arrives verbatim as a user message, and Harness does not see this conversation: make it self-contained, in the user\'s language, the full, explicit spec, asking for tests that cover each requirement. Keep a leading /goal (it sets a Harness goal) and the user\'s goal text as written. For a large task, write a concrete spec (goal, modules and the files each owns, level of detail, acceptance criteria) rather than passing the user\'s words on, and send independent parts to separate sessions in parallel, each owning its own files; wait for them together (dsh_wait run_ids), review each as it returns and send its fixes at once. With checks, a short request for a sub-agent review table is appended. To a busy session, mode followup queues the message and steer adds it to the running turn; left out, the Harness setting decides.',
302
- inputSchema: { type: 'object', required: ['message'], properties: { message: str('The task or reply to send'), session_id: str('Existing session to continue'), cwd: str('Workspace folder for a new session; leave out to use the folder this conversation works in'), workspace_id: str('Harness workspace for a new session (from dsh_list_workspaces)'), mode: { type: 'string', enum: ['followup', 'steer'], description: "followup queues after the current turn; steer injects into a running turn. Omit to follow Harness's busy-send setting" }, model: str('Only when the user names a model for this run (e.g. "DeepSeek-V4 Pro"); else the session keeps its own; a new one takes the plugin page\'s default. Matched ignoring case, spaces, hyphens and a leading DeepSeek; no match or several fails the send with the list (provider/model picks one). Sets this session only'), team: { type: 'boolean', description: 'Only when the user asks for Agent Teams: true turns them on for this session, false off' }, reasoning_effort: str('Only when the user names a reasoning effort, e.g. high; one of the efforts dsh_list_models shows for the model'), checks: { type: 'array', items: { type: 'string' }, description: 'The project\'s own test commands, e.g. npm test, or python -m pytest (a bare pytest is often not on PATH, on Windows especially); never check scripts you write yourself. dsh-baton runs them in the folder when the run ends and returns exit codes and the last output lines as evidence.' } } },
354
+ description: 'Hand a task to DeepSeek Harness, or continue a session: returns at once with a run_id and a hint saying how to wait for the reply; follow it. Call it directly, no need to list anything first. A new session starts in the folder this conversation works in, or in cwd or workspace_id (a new cwd is registered first); session_id continues that session. Without session_id, a task for a folder where this conversation already has an idle Harness session continues that session, so it keeps the earlier context (continued_session in the result says so; new_session: true starts a fresh one); a busy session is never reused, so parts sent in parallel still get a session each. message arrives verbatim as a user message, and Harness does not see this conversation: make it self-contained, in the user\'s language, the full, explicit spec, asking for tests that cover each requirement. Keep a leading /goal (it sets a Harness goal) and the user\'s goal text as written. For a large task, write a concrete spec (goal, modules and the files each owns, level of detail, acceptance criteria) rather than passing the user\'s words on, and send independent parts to separate sessions in parallel, each owning its own files; wait for them together as each send\'s hint says, review each as it returns and send its fixes at once. With checks, a short request for a sub-agent review table is appended. To a busy session, mode followup queues the message and steer adds it to the running turn; left out, the Harness setting decides.',
355
+ inputSchema: { type: 'object', required: ['message'], properties: { message: str('The task or reply to send'), session_id: str('Existing session to continue'), new_session: { type: 'boolean', description: 'Start a new session even though this conversation has an idle session in that folder: only for an unrelated task, or one that must not see the earlier work' }, cwd: str('Workspace folder for a new session; leave out to use the folder this conversation works in'), workspace_id: str('Harness workspace for a new session (from dsh_list_workspaces)'), mode: { type: 'string', enum: ['followup', 'steer'], description: "followup queues after the current turn; steer injects into a running turn. Omit to follow Harness's busy-send setting" }, model: str('Only when the user names a model for this run (e.g. "DeepSeek-V4 Pro"); else the session keeps its own; a new one takes the plugin page\'s default. Matched ignoring case, spaces, hyphens and a leading DeepSeek; no match or several fails the send with the list (provider/model picks one). Sets this session only'), team: { type: 'boolean', description: 'Only when the user asks for Agent Teams: true turns them on for this session, false off' }, reasoning_effort: str('Only when the user names a reasoning effort, e.g. high; one of the efforts dsh_list_models shows for the model'), checks: { type: 'array', items: { type: 'string' }, description: 'The project\'s own test commands, e.g. npm test, or python -m pytest (a bare pytest is often not on PATH, on Windows especially); never check scripts you write yourself. dsh-baton runs them in the folder when the run ends and returns exit codes and the last output lines as evidence.' } } },
303
356
  run: async (a, { meta } = {}) => {
304
357
  // A new session goes to this conversation's folder unless the call names another one;
305
358
  // a different folder is allowed but said back, so a wrong guess does not go unnoticed.
@@ -315,15 +368,22 @@ const TOOLS = [
315
368
  }
316
369
  const filled = here && !a.cwd && !a.workspace_id
317
370
  const folder = here && a.cwd && !within(a.cwd, here)
318
- ? { folder_note: `This conversation works in ${here}; the new session was started in ${a.cwd} as asked. If that was not intended, cancel it and send again without cwd.` }
371
+ ? { folder_note: `This conversation works in ${here}; the task runs in ${a.cwd} as asked. If that was not intended, cancel it and send again without cwd.` }
319
372
  : filled ? { cwd: here } : {}
320
373
  // The conversation's folder goes along, so a hand-over to a folder inside it joins its workspace.
321
- const args = { ...a, ...(filled ? { cwd: here } : {}), ...(here && !a.workspace_id ? { conversation_folder: here } : {}) }
322
- const sent = await core.api.send({ ...args, sender: core.senderOf(core.setting('SENDER') || clientName) })
374
+ const { new_session: fresh, ...given } = a
375
+ const args = { ...given, ...(filled ? { cwd: here } : {}), ...(here && !a.workspace_id ? { conversation_folder: here } : {}) }
376
+ // A new task for a folder this conversation already has an idle session in continues it.
377
+ const folderOf = a.session_id ? null : folderKey(args)
378
+ const reused = a.session_id || fresh ? null : await idleSessionFor(meta, folderOf)
379
+ const { cwd: _cwd, workspace_id: _ws, conversation_folder: _cf, ...rest } = args
380
+ const sent = await core.api.send({ ...(reused ? { ...rest, session_id: reused } : args), sender: core.senderOf(core.setting('SENDER') || clientName) })
381
+ rememberSession(meta, sent.session_id, folderOf)
323
382
  // Only when it waits behind a turn (queued_behind; a plugin before 0.6.14 says only
324
383
  // other_active_runs): every run starts out queued until Harness takes its prompt.
325
384
  const behind = a.session_id && sent.state === 'queued' && sent.mode === 'followup' && (sent.queued_behind || sent.other_active_runs?.length)
326
- const st = { ...sent, ...folder, ...(behind ? { queue_hint: QUEUE_HINT() } : {}) }
385
+ const continued = reused ? { continued_session: reused, session_note: `Continued session ${reused}, which this conversation used for this folder before and which is idle now, so Harness keeps that context. For an unrelated task that must not see the earlier work, send with new_session: true.` } : {}
386
+ const st = { ...sent, ...(reused ? {} : folder), ...continued, ...(behind ? { queue_hint: QUEUE_HINT() } : {}) }
327
387
  // Codex has no wake-on-exit for shell commands: offered wait_command, it runs it in a
328
388
  // terminal and polls that, so it gets dsh_wait only.
329
389
  if (isCodex()) {
@@ -343,10 +403,20 @@ const TOOLS = [
343
403
  hint: `Run started. Run wait_command now as a background terminal command and end your turn: Antigravity wakes you when it exits, which is when the run ends or stops to ask the user something; it prints the reply or the questions, with no polling and no turns spent meanwhile. Do not call dsh_wait for it. Several runs: one background wait_command each, so whichever ends first wakes you. ${GOAL_WAIT_HINT('--until turn --every 10m on wait_command')}`,
344
404
  }
345
405
  }
406
+ // Claude Code: told plainly as well. Offered "otherwise dsh_wait", a conversation that sent
407
+ // 12 runs at once took one dsh_wait for all of them, timing out and calling again every
408
+ // 50 s (2026-11-21), where a background wait costs nothing until a run ends.
409
+ if (isClaudeCode()) {
410
+ return {
411
+ ...st,
412
+ wait_command: waitCommand(st.run_id),
413
+ hint: `Run started. Run wait_command now with Bash run_in_background: true, then go on with other work, or end your turn if there is none: Claude Code wakes you when it exits, which is when the run ends or stops to ask the user something; it prints the reply or the questions, with no polling and no turns spent meanwhile. Do not call dsh_wait for it. Several runs: one background wait_command each, never one dsh_wait for all, so whichever ends first wakes you. ${GOAL_WAIT_HINT('--until turn --every 10m on wait_command')}`,
414
+ }
415
+ }
346
416
  return {
347
417
  ...st,
348
418
  wait_command: waitCommand(st.run_id),
349
- hint: `Run started. If you can run a shell command in the background and are woken when it exits (Claude Code: Bash with run_in_background), run wait_command that way: it ends when the run ends, or stops to ask the user something, and prints the reply or the questions, with no polling (several runs: one background wait_command each, so whichever ends first wakes you). Otherwise call dsh_wait with this run_id (several runs: one dsh_wait with run_ids). ${GOAL_WAIT_HINT('--until turn --every 10m on wait_command')}`,
419
+ hint: `Run started. If you can run a shell command in the background and are woken when it exits (Claude Code: Bash with run_in_background), run wait_command that way: it ends when the run ends, or stops to ask the user something, and prints the reply or the questions, with no polling (several runs: one background wait_command each, so whichever ends first wakes you). Then do not also call dsh_wait for it: go on with other work, or end your turn if there is none. Otherwise call dsh_wait with this run_id (several runs: one dsh_wait with run_ids). ${GOAL_WAIT_HINT('--until turn --every 10m on wait_command')}`,
350
420
  }
351
421
  },
352
422
  },
@@ -363,7 +433,7 @@ const TOOLS = [
363
433
  {
364
434
  name: 'dsh_wait',
365
435
  annotations: annotations('Wait for run'),
366
- description: () => `Wait for a run sent with dsh_send to end and return its state and final reply.${backgroundWaits() ? ' Prefer the background wait_command from dsh_send if your client wakes you when a background command exits: it costs no turns.' : ''} It also returns at once when the run stops to ask a person: needs_input answer (reply with dsh_answer) or harness-ui (an approval in the Harness window). Each call waits up to ${waitSeconds()} s${isCodex() && waitSeconds() > 270 ? ' (270 s in a conversation that was already open when dsh-baton set Codex\'s tool timeout)' : ''}; if it returns timed_out: true, call dsh_wait again with the same run_id, without a progress note. Parallel runs: all ids in run_ids, never one by one; returns once any ends or asks (ended; the rest in still_running); then wait again with the rest plus your fixes. A run in a session with a Harness goal is followed on until the goal stops, with every round since the run began. With session_id instead of run_id it follows that session's Harness goal (see until) without sending anything; it also returns when Harness needs a person or will not go on by itself. Pass back the cursor each result gives.${isCodex() ? ` ${NO_POLL} ${codeModeYield()}` : ''}`,
436
+ description: () => `Wait for a run sent with dsh_send to end and return its state and final reply.${backgroundWaits() ? ' Prefer the background wait_command from dsh_send if your client wakes you when a background command exits: it costs no turns. For a run a background wait_command already waits for, dsh_wait returns at once without waiting: do not call it for that run.' : ''} It also returns at once when the run stops to ask a person: needs_input answer (reply with dsh_answer) or harness-ui (an approval in the Harness window). Each call waits up to ${waitSeconds()} s${isCodex() && waitSeconds() > 270 ? ' (270 s in a conversation that was already open when dsh-baton set Codex\'s tool timeout)' : ''}; if it returns timed_out: true, call dsh_wait again with the same run_id, without a progress note. Parallel runs: all ids in run_ids, never one by one; returns once any ends or asks (ended; the rest in still_running); then wait again with the rest plus your fixes. A run in a session with a Harness goal is followed on until the goal stops, with every round since the run began. With session_id instead of run_id it follows that session's Harness goal (see until) without sending anything; it also returns when Harness needs a person or will not go on by itself. Pass back the cursor each result gives.${isCodex() ? ` ${NO_POLL} ${codeModeYield()}` : ''}`,
367
437
  inputSchema: {
368
438
  type: 'object', properties: {
369
439
  run_id: str('Run id from dsh_send'),
@@ -376,6 +446,8 @@ const TOOLS = [
376
446
  },
377
447
  run: async (a, { progress, signal, meta }) => {
378
448
  const ids = [...new Set([...(Array.isArray(a.run_ids) ? a.run_ids : []), ...(a.run_id ? [a.run_id] : [])].filter((id) => typeof id === 'string' && id))]
449
+ const background = await waitedInBackground(ids)
450
+ if (background) return background
379
451
  if (ids.length > 1) {
380
452
  const r = await waitAnyInChunks(ids, progress, signal, meta)
381
453
  return r.cancelled || r.timed_out ? r : anyResult(r)
package/src/server.mjs CHANGED
@@ -141,7 +141,10 @@ async function reloadIfInstalled() {
141
141
  current = next
142
142
  currentStamp = now
143
143
  currentVersion = init?.serverInfo?.version ?? null
144
- note = `dsh-baton was updated from ${before} to ${currentVersion} without a restart; this call already used ${currentVersion}.` +
144
+ // The same version with changed files (a reinstall, or files copied by hand) says so plainly.
145
+ note = (before && before === currentVersion
146
+ ? `dsh-baton ${currentVersion} was reloaded with changed files without a restart; this call already used them.`
147
+ : `dsh-baton was updated from ${before} to ${currentVersion} without a restart; this call already used ${currentVersion}.`) +
145
148
  (added.length ? ` New in this version: ${added.join(', ')}. If this conversation does not show them, call them through dsh_call {name, arguments}.` : '')
146
149
  if (lastTools !== null && JSON.stringify(tools) !== lastTools) {
147
150
  lastTools = JSON.stringify(tools)
@@ -0,0 +1,44 @@
1
+ // Background waits: a wait_command the client runs in the background leaves a file named
2
+ // <run_id>.<pid> in ~/.dsh-baton/waiting while it waits. dsh_wait reads them, so a client
3
+ // that already waits in the background for a run is told so at once instead of waiting a
4
+ // second time in the foreground (Claude Code did that on 2026-11-19, a minute a call, while
5
+ // its background waits were still running).
6
+ import fs from 'node:fs'
7
+ import path from 'node:path'
8
+ import { batonHome } from '../host/lib/socket.js'
9
+
10
+ const dir = (home = batonHome()) => path.join(home, 'waiting')
11
+ const safe = (id) => /^[\w.-]+$/.test(id ?? '')
12
+
13
+ const alive = (pid) => {
14
+ try { process.kill(pid, 0); return true } catch (e) { return e.code === 'EPERM' }
15
+ }
16
+
17
+ // Marks this process as waiting for runId until it exits. Returns the function that clears it.
18
+ export function markWaiting(runId, { pid = process.pid, home } = {}) {
19
+ if (!safe(runId)) return () => {}
20
+ const file = path.join(dir(home), `${runId}.${pid}`)
21
+ try {
22
+ fs.mkdirSync(dir(home), { recursive: true })
23
+ fs.writeFileSync(file, String(Date.now()))
24
+ } catch { return () => {} }
25
+ const clear = () => { try { fs.unlinkSync(file) } catch { /* gone already */ } }
26
+ process.once('exit', clear)
27
+ return clear
28
+ }
29
+
30
+ // Whether a live process waits for runId in the background. Files left by a process that is
31
+ // gone (killed without its exit handler) are removed on the way.
32
+ export function waitingInBackground(runId, { home } = {}) {
33
+ if (!safe(runId)) return false
34
+ let names
35
+ try { names = fs.readdirSync(dir(home)) } catch { return false }
36
+ let found = false
37
+ for (const name of names) {
38
+ if (!name.startsWith(`${runId}.`)) continue
39
+ const pid = Number(name.slice(runId.length + 1))
40
+ if (pid > 0 && alive(pid)) { found = true; continue }
41
+ try { fs.unlinkSync(path.join(dir(home), name)) } catch { /* removed meanwhile */ }
42
+ }
43
+ return found
44
+ }