dsh-baton-mcp 0.6.16 → 0.6.17

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
@@ -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
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-baton-host",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
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.17"
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.17",
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.17",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "dsh-baton-mcp",
15
- "version": "0.6.16",
15
+ "version": "0.6.17",
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']
@@ -117,6 +118,40 @@ const FOLLOW_COMMAND_HINT = ' Your client wakes you when a background command ex
117
118
  // wait returned (measured 2026-11-08: a result read 3 minutes late, its rework sent late).
118
119
  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
120
 
121
+ // Sessions this conversation sent to, so that a new task for the same folder continues the
122
+ // session it used there before, when that one is idle, rather than starting a session per task
123
+ // (2026-11-19: three tasks in one project, one after another, went to three new sessions).
124
+ // Kept per conversation: Codex and Antigravity run one server for several conversations and
125
+ // send the conversation's id with each call; Claude Code runs one server per conversation.
126
+ // Kept in memory only: after a server restart (an update) the next task starts one more session.
127
+ const AG_META = 'antigravity.google/'
128
+ const conversationKey = (meta) => threadOf(meta) ?? meta?.[`${AG_META}root_conversation_id`] ?? meta?.[`${AG_META}conversation_id`] ?? 'this'
129
+ const usedSessions = new Map()
130
+ const folderKey = (a) => (a.workspace_id ? `workspace:${a.workspace_id}` : a.cwd ? `folder:${folderId(a.cwd)}` : null)
131
+ function rememberSession(meta, sessionId, folder) {
132
+ if (!sessionId) return
133
+ const key = conversationKey(meta)
134
+ if (!usedSessions.has(key)) usedSessions.set(key, new Map())
135
+ const mine = usedSessions.get(key)
136
+ const known = mine.get(sessionId)
137
+ if (folder || known) mine.set(sessionId, { folder: folder ?? known.folder, at: Date.now() })
138
+ }
139
+ // The session this conversation last used for folder, if it is idle now: no turn, no run of
140
+ // ours, no question, no goal going on, not archived. A busy one is never taken, so parts sent
141
+ // in parallel still get a session each.
142
+ async function idleSessionFor(meta, folder) {
143
+ const mine = usedSessions.get(conversationKey(meta))
144
+ if (!mine || !folder) return null
145
+ const candidates = [...mine].filter(([, v]) => v.folder === folder).sort((x, y) => y[1].at - x[1].at)
146
+ for (const [sid] of candidates) {
147
+ const st = await core.api.status({ session_id: sid }).catch(() => null)
148
+ if (!st || st.archived) { mine.delete(sid); continue }
149
+ if (st.busy || st.turn_running || st.bridge_runs?.length || st.needs_input || st.goal?.phase === 'active') continue
150
+ return sid
151
+ }
152
+ return null
153
+ }
154
+
120
155
  // Wait in short chunks, reporting progress between them (clients that support it can
121
156
  // show it or reset their timer). An unfinished wait returns only the state, not the run's
122
157
  // recent events, so the client has nothing to summarise and simply waits again.
@@ -150,6 +185,22 @@ async function waitInChunks({ run_id }, progress, signal, meta) {
150
185
  }
151
186
  }
152
187
 
188
+ // Runs a background wait_command of this machine already waits for (waiters.mjs): dsh_wait says
189
+ // so at once instead of waiting a second time in the foreground. Only for clients that wait in
190
+ // the background, and only while none of the runs has ended or asks (then the ordinary wait
191
+ // returns it at once).
192
+ 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.`
193
+ const STOPPED = new Set(['completed', 'failed', 'cancelled', 'interrupted', 'waiting'])
194
+ async function waitedInBackground(ids) {
195
+ if (!backgroundWaits() || !ids.length || !ids.every((id) => waitingInBackground(id))) return null
196
+ const states = await Promise.all(ids.map((id) => core.api.status({ run_id: id, tail: 1 }).catch(() => null)))
197
+ if (states.some((st) => !st || STOPPED.has(st.state) || st.needs_input)) return null
198
+ const hint = BACKGROUND_WAIT_HINT(ids.length)
199
+ return ids.length === 1
200
+ ? { run_id: ids[0], state: states[0].state, waiting_in_background: true, hint }
201
+ : { 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 }
202
+ }
203
+
153
204
  // Several runs (dsh_wait run_ids): returns as soon as any of them ends or stops to ask a person,
154
205
  // with every one that has by then and the ones still running. Each round asks about all of them
155
206
  // together for a short chunk, so an ending is seen within MULTI_CHUNK_S. Every answer is kept:
@@ -298,8 +349,8 @@ const TOOLS = [
298
349
  {
299
350
  name: 'dsh_send',
300
351
  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.' } } },
352
+ 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 (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.',
353
+ 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
354
  run: async (a, { meta } = {}) => {
304
355
  // A new session goes to this conversation's folder unless the call names another one;
305
356
  // a different folder is allowed but said back, so a wrong guess does not go unnoticed.
@@ -318,12 +369,19 @@ const TOOLS = [
318
369
  ? { 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.` }
319
370
  : filled ? { cwd: here } : {}
320
371
  // 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) })
372
+ const { new_session: fresh, ...given } = a
373
+ const args = { ...given, ...(filled ? { cwd: here } : {}), ...(here && !a.workspace_id ? { conversation_folder: here } : {}) }
374
+ // A new task for a folder this conversation already has an idle session in continues it.
375
+ const folderOf = a.session_id ? null : folderKey(args)
376
+ const reused = a.session_id || fresh ? null : await idleSessionFor(meta, folderOf)
377
+ const { cwd: _cwd, workspace_id: _ws, conversation_folder: _cf, ...rest } = args
378
+ const sent = await core.api.send({ ...(reused ? { ...rest, session_id: reused } : args), sender: core.senderOf(core.setting('SENDER') || clientName) })
379
+ rememberSession(meta, sent.session_id, folderOf)
323
380
  // Only when it waits behind a turn (queued_behind; a plugin before 0.6.14 says only
324
381
  // other_active_runs): every run starts out queued until Harness takes its prompt.
325
382
  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() } : {}) }
383
+ 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.` } : {}
384
+ const st = { ...sent, ...(reused ? {} : folder), ...continued, ...(behind ? { queue_hint: QUEUE_HINT() } : {}) }
327
385
  // Codex has no wake-on-exit for shell commands: offered wait_command, it runs it in a
328
386
  // terminal and polls that, so it gets dsh_wait only.
329
387
  if (isCodex()) {
@@ -346,7 +404,7 @@ const TOOLS = [
346
404
  return {
347
405
  ...st,
348
406
  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')}`,
407
+ 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
408
  }
351
409
  },
352
410
  },
@@ -363,7 +421,7 @@ const TOOLS = [
363
421
  {
364
422
  name: 'dsh_wait',
365
423
  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()}` : ''}`,
424
+ 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
425
  inputSchema: {
368
426
  type: 'object', properties: {
369
427
  run_id: str('Run id from dsh_send'),
@@ -376,6 +434,8 @@ const TOOLS = [
376
434
  },
377
435
  run: async (a, { progress, signal, meta }) => {
378
436
  const ids = [...new Set([...(Array.isArray(a.run_ids) ? a.run_ids : []), ...(a.run_id ? [a.run_id] : [])].filter((id) => typeof id === 'string' && id))]
437
+ const background = await waitedInBackground(ids)
438
+ if (background) return background
379
439
  if (ids.length > 1) {
380
440
  const r = await waitAnyInChunks(ids, progress, signal, meta)
381
441
  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
+ }