From 723b276e6f3809f73612c0e9a3081853e64019e0 Mon Sep 17 00:00:00 2001 From: zksnet Date: Sun, 11 Oct 2026 00:24:03 +0800 Subject: [PATCH] fix: restore responsive Bash foreground waits --- README.md | 27 +++++++++++++ README.zh-CN.md | 27 +++++++++++++ client.js | 4 +- lib/core.js | 24 ++++++----- package.json | 1 + test/bash-timeout.test.js | 83 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 151 insertions(+), 15 deletions(-) create mode 100644 test/bash-timeout.test.js diff --git a/README.md b/README.md index 888395d..556b75c 100644 --- a/README.md +++ b/README.md @@ -623,6 +623,32 @@ The composer **Undo once** and **Undo last round** stay in the current conversat If the **same task works in standard but fails in minimal or PTC**, preset `run_code`, sandbox, or plan intercept text is often still uncleared, or built-in minimal is missing `agent-instructions`. Use **1.1.61+**, then **quit the host fully → Apply in Clean → restart → start a new chat**. Switching preset alone does not reload patches in the running process. +### Response speed + +DSH runs Bash calls in a tool batch one at a time. Older dsh-purge releases raised the default foreground wait from 60 seconds to 10 minutes, so one slow command could hold up later calls for that long. Patch #21 now restores marked plugin values to the official 60-second default. Unmarked timeouts and other custom values are preserved; an unmarked 10-minute value cannot reliably be distinguished from a user setting. + +For a shorter wait in `dsh web` on macOS/Linux, add this entry to `$DSH_HOME/profiles/web/cordis.patch.yml` (normally `~/.dsh/profiles/web/cordis.patch.yml`). Edit an existing entry with the same id instead of adding a duplicate. This profile layer is applied after the bundled configuration, so future plugin applies keep the override. + +```yaml +- id: bash-sandbox + config: + timeoutMs: 10000 +``` + +With the standard jobs service and `promoteOnTimeout: true`, an unfinished command returns a background job id after 10 seconds and keeps running. Read it with `job_output` or stop it with `job_kill`. This changes the foreground wait, not the command's speed. Without that service or with promotion disabled, the timeout kills the command. A per-call `timeoutMs` overrides this default; `run_in_background: true` returns a job id immediately. + +For routine tasks, you can also opt into Low reasoning for new sessions: + +```yaml +- id: agent-default-model + config: + provider: deepseek-official + model: deepseek-flash + reasoningEffort: low +``` + +Restart `dsh web` to load the profile. The model and reasoning defaults apply to newly created sessions; select Low in the composer for an existing session. The plugin does not change these model preferences automatically. Keep High when the task needs deeper reasoning, and narrow file searches rather than recursively scanning every application directory. + ### Own servers Addresses in mainland China, Hong Kong, and Macau stay forbidden unless that one host was registered first. Saying “this is my server” in chat does not allow it. A key or a password does not allow it either. @@ -645,6 +671,7 @@ The box sits under Prompt. If the dock does not show it yet, quit DeepSeek Harne ## Local checks ```sh +npm test node --check lib/index.js node --check lib/core.js node --check lib/surface.js diff --git a/README.zh-CN.md b/README.zh-CN.md index 21cb0a1..d0b1dc8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -640,6 +640,32 @@ purge_status purge_apply purge_revert **极简 / PTC 与标准不一致时**:同一任务在标准模式能跑、在极简或 PTC 被拦,通常是 preset 里 `run_code` 或 plan 拦截句没洗净,或内置 minimal 缺少 `agent-instructions`。请升到 **1.1.61+**,**完全退出宿主 → 清洗里应用 → 自动重启 → 新开一轮对话** 再试;只换 preset 不重应用,旧进程里的补丁不会更新。 +### 响应速度 + +DSH 会按顺序执行同一批中的 Bash 调用。旧版 dsh-purge 把默认前台等待从 60 秒提高到了 10 分钟,一条慢命令会让后续调用一起等待。补丁 #21 现在把带插件标记的旧值恢复为官方的 60 秒。无标记的等待时间和其他自定义值会保留;无标记的 10 分钟无法可靠地区分是插件旧值还是用户设置。 + +在 macOS/Linux 的 `dsh web` 中,如需更快返回工具结果,可在 `$DSH_HOME/profiles/web/cordis.patch.yml`(通常是 `~/.dsh/profiles/web/cordis.patch.yml`)添加下面的条目。已有相同 id 时修改原条目,不要重复添加。这个 profile 覆盖层在内置配置之后加载,后续应用插件会保留它。 + +```yaml +- id: bash-sandbox + config: + timeoutMs: 10000 +``` + +使用标准 jobs 服务且 `promoteOnTimeout: true` 时,未完成的命令会在 10 秒后返回后台任务 id,并继续运行。用 `job_output` 读取结果、用 `job_kill` 停止。这个设置缩短前台等待,不会让命令本身跑得更快。没有 jobs 服务或关闭自动转后台时,超时会终止命令。单次调用传入的 `timeoutMs` 优先于这里的默认值;`run_in_background: true` 可立即返回任务 id。 + +日常任务还可以选择让新会话默认使用 Low 推理: + +```yaml +- id: agent-default-model + config: + provider: deepseek-official + model: deepseek-flash + reasoningEffort: low +``` + +重启 `dsh web` 后加载配置。模型和推理等级默认值只用于新建会话,已有会话请在输入框中选择 Low。插件不会自动修改这些模型偏好。需要深入推理的任务可保留 High;搜索文件时应限定目录,避免递归扫描所有应用目录。 + ### 自己的服务器 中国大陆、香港、澳门的地址默认禁止。只有事先登记的那一台可以例外。在对话里说「这是我的服务器」不会放行。密钥和密码也不会。 @@ -662,6 +688,7 @@ purge_status purge_apply purge_revert ## 本地校验 ```sh +npm test node --check lib/index.js node --check lib/core.js node --check lib/rewind.js diff --git a/client.js b/client.js index 3f8f266..98f97a2 100644 --- a/client.js +++ b/client.js @@ -352,7 +352,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "patch.17": "观察策略读写放行", "patch.18": "重复调用守卫禁用", "patch.19": "工具结果修剪禁用", - "patch.21": "bash 超时 60s → 10min", + "patch.21": "恢复插件延长的 bash 等待", "patch.22": "read 上限放宽", "patch.23": "子代理深度 3 → 10", "patch.24": "preset fetch 启用", @@ -680,7 +680,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "patch.17": "Observation policy allow R/W", "patch.18": "Repeat-call guard off", "patch.19": "Tool-result pruner off", - "patch.21": "bash timeout 60s → 10min", + "patch.21": "Restore plugin-raised bash wait", "patch.22": "read cap raised", "patch.23": "subagent depth 3 → 10", "patch.24": "preset fetch on", diff --git a/lib/core.js b/lib/core.js index 8b9b308..fc25427 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3099,25 +3099,23 @@ const NEW_TOOL_PATCHES = [ markers: ["[dsh-purge] tool-result pruning disabled"], }, { - id: 21, name: "BASH_TIMEOUT_RAISED", layer: "代码", layer_en: "Code", - desc: "bash 超时 60s → 10min / bash timeout raised", + id: 21, name: "BASH_TIMEOUT_RESTORE", layer: "代码", layer_en: "Code", + desc: "恢复插件延长的 bash 等待 / restore plugin-raised bash wait", file: "base", rel: ["cordis.patch.yml"], + // Migration only: clean installs and custom timeouts need no changes. + softSettle: true, replacements: [ { - // 幂等性:原 pattern 以 `timeoutMs: 60000` 结尾,替换产物 `600000` 仍然 - // 包含它,于是每次 autoApplyOnStart 都会再拼一个 0(实测已涨到 - // 600000000000000)。 - // 现在的做法:锚在 bash-sandbox 行内,`[^\n]*` 必须吃到行尾 —— 这样上一次 - // 追加的注记会被整体重写而不是再叠一层,数值也不再有可再匹配的"前缀"。 - // 这条是带 g 的模块级正则,匹配和写入都要克隆后再用,否则 lastIndex 残留会导致永远 pending。 - // YAML 只认 #。写成 // 时从数字到行尾都是字符串,timeoutMs 校验失败,宿主起不来。 - // [^\n]* 会把已经写成 // 的那一行整段重写成下面的 # 版本。 - pattern: /(name: '@deepseek-ai\/dsh-bash-sandbox'[\s\S]*?\n {8}timeoutMs: )6[0-9]+[^\n]*/g, - replace: "$1600000 # [dsh-purge] bash timeout raised", + // Bash calls are exclusive in DSH. Raising this foreground wait to + // 10 minutes also blocked every later call in the same tool batch. + // Undo only marked plugin values, including the old extra-zero bug. + // Unmarked values or a user's changed value remain untouched. Bound + // the match to this entry so a missing timeout cannot reach the next. + pattern: /(name: ['"]@deepseek-ai\/dsh-bash-sandbox['"][^\n]*\n(?:(?! {0,4}\S)[^\n]*\n)*? {8}timeoutMs: )60{5,}[ \t]*(?:#|\/\/)[ \t]*\[dsh-purge\] bash timeout raised[ \t]*(?=\n|$)/g, + replace: "$160000", }, ], - markers: ["timeoutMs: 600000 # [dsh-purge] bash timeout raised"], }, { id: 22, name: "READ_CAPS_RAISED", layer: "代码", layer_en: "Code", diff --git a/package.json b/package.json index f34c438..ea5f25c 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "LICENSE" ], "scripts": { + "test": "node --test", "embed-prompt": "node scripts/embed-default-prompt.mjs", "build:client": "node scripts/build-client.mjs" }, diff --git a/test/bash-timeout.test.js b/test/bash-timeout.test.js new file mode 100644 index 0000000..cd99f6e --- /dev/null +++ b/test/bash-timeout.test.js @@ -0,0 +1,83 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { ALL_PATCHES, applyReplacementsToText } from "../lib/core.js"; + +const patch = ALL_PATCHES.find(({ id }) => id === 21); +const filename = "dsh-base/cordis.patch.yml"; +const marker = "# [dsh-purge] bash timeout raised"; + +function fixture(timeout, name = "@deepseek-ai/dsh-bash-sandbox") { + return `- insert: + - id: bash-sandbox + name: '${name}' + disabled: false + config: + timeoutMs: ${timeout} + - id: other-tool + config: + timeoutMs: 600000 +`; +} + +function apply(text) { + return applyReplacementsToText(text, patch, filename); +} + +test("preserves the official 60-second default", () => { + const text = fixture("60000"); + assert.deepEqual(apply(text), { text, changed: false }); +}); + +test("restores the plugin's 10-minute wait without changing adjacent config", () => { + assert.deepEqual(apply(fixture(`600000 ${marker}`)), { + text: fixture("60000"), + changed: true, + }); +}); + +test("migrates marked older extra-zero and invalid-comment variants", () => { + for (const value of ["600000", "600000000000000"]) { + for (const comment of [marker, marker.replace("#", "//")]) { + assert.deepEqual(apply(fixture(`${value} ${comment}`)), { + text: fixture("60000"), + changed: true, + }); + } + } +}); + +test("repeated apply is idempotent", () => { + let text = apply(fixture(`600000 ${marker}`)).text; + for (let i = 0; i < 3; i += 1) { + assert.deepEqual(apply(text), { text, changed: false }); + } +}); + +test("preserves custom values, including an unmarked 10-minute wait", () => { + for (const value of ["10000", "45000", "600000", "660000", `10000 ${marker}`, `660000 ${marker}`]) { + const text = fixture(value); + assert.deepEqual(apply(text), { text, changed: false }); + } +}); + +test("never migrates another executor or crosses an entry boundary", () => { + const other = fixture(`600000 ${marker}`, "@deepseek-ai/dsh-pwsh-sandbox"); + assert.deepEqual(apply(other), { text: other, changed: false }); + const missing = fixture("60000") + .replace(" timeoutMs: 60000\n", "") + .replace(" timeoutMs: 600000", ` timeoutMs: 600000 ${marker}`); + assert.deepEqual(apply(missing), { text: missing, changed: false }); +}); + +test("preserves CRLF and accepts a timeout on the last line", () => { + const source = fixture(`600000 ${marker}`).split(" - id: other-tool")[0].trimEnd(); + const expected = fixture("60000").split(" - id: other-tool")[0].trimEnd(); + assert.equal(apply(source).text, expected); + assert.equal(apply(source.replaceAll("\n", "\r\n")).text, expected.replaceAll("\n", "\r\n")); +}); + +test("migrates each marked Bash entry without leaking regex state", () => { + const source = fixture(`600000 ${marker}`); + assert.equal(apply(source + source).text, fixture("60000") + fixture("60000")); + assert.equal(apply(source).changed, true); +});