Skip to content

👾 Open Computer Use – Open-Source Alternative to Codex Computer Use

fix(dsh): skill 安装改为非破坏性,避免覆盖用户已有技能

陈伟记59706c6a4db0
diff --git a/docs/histories/2026-09/20260914-1850-dsh-host-integration.md b/docs/histories/2026-09/20260914-1850-dsh-host-integration.md
index 506a74b..72c71e0 100644
--- a/docs/histories/2026-09/20260914-1850-dsh-host-integration.md
+++ b/docs/histories/2026-09/20260914-1850-dsh-host-integration.md
@@ -21,6 +21,7 @@
- **npm 侧对齐**:`scripts/npm/build-packages.mjs` 增加 `install-dsh-mcp` 命令、帮助文本、`help install-dsh-mcp` 分支、打包清单与拷贝逻辑(含把 `skills/open-computer-use` 打进包里,否则 npm 用户没有 skill 可用)。
- **文档**:`skills/open-computer-use/references/installation.md` 增加 DSH 章节;`README.md` 宿主命令列表补齐。
- **验证能力**:新增 `scripts/tests/install-dsh-mcp.test.sh` 并接入 `scripts/ci.sh`。
+- **非破坏性 skill 安装**:目标目录已存在且与 checkout 不一致时只警告不覆盖,`--force-skill` 才替换并留时间戳备份。理由:本机就存在一份比仓库更详细的中文运维版技能,直接覆盖等于静默毁掉用户自己的内容。
### 🧠 Design Intent (Why)
- **钩子必须和 MCP 一起装**:OCU 的软件光标只在 turn 边界隐藏,触发源是 MCP 通知 `notifications/turn-ended`(`packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swift` → `SoftwareCursorOverlay.reset()`;设计取舍见 `SoftwareCursorOverlay.swift:425-429`——进程内没有 inactivity timer,因为一轮里模型思考数分钟是常态)。而 `dsh-mcp-client` 从不发送该通知,任何会话或子代理调过一次动作后光标会永久留在屏幕上。只写 MCP 配置的安装器会把这个缺陷一起交付给用户。
@@ -38,7 +39,7 @@
- `README.md`
### ✅ Verification
-- `scripts/tests/install-dsh-mcp.test.sh`:5 项断言全部通过(保留用户行 + 两条托管行、钩子命令带引号、skill 落位、重复执行字节不变、`--no-hook`/`--no-skill` 生效)。
+- `scripts/tests/install-dsh-mcp.test.sh`:9 项断言全部通过(保留用户行 + 两条托管行、钩子命令带引号、skill 落位、重复执行字节不变、`--no-hook`/`--no-skill` 生效、手写重复行被拒、已有 skill 不被覆盖、`--force-skill` 替换并留备份)。
- `bash -n` / `node --check`:新增与改动的脚本通过。
- 产物 YAML 经独立解析器校验:顶层 2 个条目,`insert` 中 id 为 `["mcp-open-computer-use", "ocu-turn-ended-hook"]`。
- 与真机对照:在相同的目录结构下安装后,产物与当前手工维护的 DSH 配置等价。
diff --git a/scripts/install-dsh-mcp.sh b/scripts/install-dsh-mcp.sh
index 53084ce..26674c4 100755
--- a/scripts/install-dsh-mcp.sh
+++ b/scripts/install-dsh-mcp.sh
@@ -12,6 +12,7 @@ profile_name="web"
command_override=""
with_hook=1
with_skill=1
+force_skill=0
usage() {
cat <<'EOF'
@@ -30,6 +31,8 @@ Options:
--command <path> Executable DSH spawns for the MCP server (default: auto-detect)
--no-hook Do not write the turn-boundary hook config or its patch row
--no-skill Do not copy the skill into <dsh-home>/skills
+ --force-skill Replace an existing skill directory that differs from this
+ checkout (the previous copy is kept as a timestamped backup)
-h, --help Show this help.
Environment:
@@ -79,6 +82,10 @@ while [[ $# -gt 0 ]]; do
with_skill=0
shift
;;
+ --force-skill)
+ force_skill=1
+ shift
+ ;;
-h|--help)
usage
exit 0
@@ -171,11 +178,26 @@ if [[ "${with_hook}" -eq 0 ]]; then
echo "Turn-boundary hook skipped (--no-hook); the software cursor can stay on screen between turns." >&2
fi
+skill_target="${dsh_home}/skills/open-computer-use"
+
if [[ "${with_skill}" -eq 1 ]]; then
- if [[ -d "${skill_source}" ]]; then
+ if [[ ! -d "${skill_source}" ]]; then
+ echo "Skill source not found at ${skill_source}; skipping the skill copy." >&2
+ elif [[ ! -e "${skill_target}" ]]; then
+ node "${config_helper}" copy-into-dir "${dsh_home}/skills" "${skill_source}"
+ elif diff -rq "${skill_source}" "${skill_target}" >/dev/null 2>&1; then
+ echo "Skill already current at ${skill_target}"
+ elif [[ "${force_skill}" -eq 1 ]]; then
+ skill_backup="${skill_target}.bak-$(date +%Y%m%d-%H%M%S)"
+ mv "${skill_target}" "${skill_backup}"
+ echo "Existing skill moved to ${skill_backup}" >&2
node "${config_helper}" copy-into-dir "${dsh_home}/skills" "${skill_source}"
else
- echo "Skill source not found at ${skill_source}; skipping the skill copy." >&2
+ cat >&2 <<EOF
+Skill at ${skill_target} differs from this checkout; leaving it untouched so a
+local copy is never overwritten silently. Re-run with --force-skill to replace it
+(a timestamped backup is kept).
+EOF
fi
fi
diff --git a/scripts/tests/install-dsh-mcp.test.sh b/scripts/tests/install-dsh-mcp.test.sh
index cce3811..886d475 100755
--- a/scripts/tests/install-dsh-mcp.test.sh
+++ b/scripts/tests/install-dsh-mcp.test.sh
@@ -88,4 +88,16 @@ if [[ -f "${conflict_home}/ocu-hooks.json" ]]; then
fi
pass "a hand-written duplicate row is refused instead of duplicated"
+printf 'local edit\n' >> "${dsh_home}/skills/open-computer-use/SKILL.md"
+"${installer}" --dsh-home "${dsh_home}" --command "${fake_command}" >/dev/null 2>&1
+grep -q "local edit" "${dsh_home}/skills/open-computer-use/SKILL.md" || fail "an existing skill was overwritten without --force-skill"
+pass "an existing skill that differs is left untouched"
+
+"${installer}" --dsh-home "${dsh_home}" --command "${fake_command}" --force-skill >/dev/null 2>&1
+if grep -q "local edit" "${dsh_home}/skills/open-computer-use/SKILL.md"; then
+ fail "--force-skill did not replace the skill"
+fi
+[[ "$(find "${dsh_home}/skills" -maxdepth 1 -name 'open-computer-use.bak-*' | wc -l | tr -d ' ')" == "1" ]] || fail "--force-skill left no backup"
+pass "--force-skill replaces the skill and keeps a backup"
+
echo "install-dsh-mcp tests passed"
diff --git a/skills/open-computer-use/references/installation.md b/skills/open-computer-use/references/installation.md
index c76f220..818fd90 100644
--- a/skills/open-computer-use/references/installation.md
+++ b/skills/open-computer-use/references/installation.md
@@ -96,13 +96,16 @@ It also installs two things a DSH host needs beyond the MCP entry:
`open-computer-use turn-ended`. Pass `--no-hook` to skip both.
- **The skill.** Copied to `<dsh-home>/skills/open-computer-use`, which DSH scans
as a user-level skill root, so every new conversation can see it. Pass
- `--no-skill` to skip.
+ `--no-skill` to skip. An existing skill directory is never overwritten
+ silently: when it differs from this checkout the installer leaves it in place
+ and says so, and `--force-skill` replaces it while keeping a timestamped
+ backup.
Options: `--profile <name>`, `--dsh-home <dir>`, `--command <path>`, `--no-hook`,
-`--no-skill`. DSH spawns the registered command directly rather than through a
-shell, so `--command` must be an absolute path to an executable; when it is
-omitted the installer probes the usual install locations and the npm global
-layout, and fails with guidance if it finds nothing.
+`--no-skill`, `--force-skill`. DSH spawns the registered command directly rather
+than through a shell, so `--command` must be an absolute path to an executable;
+when it is omitted the installer probes the usual install locations and the npm
+global layout, and fails with guidance if it finds nothing.
For any other MCP client, add a stdio server manually: