在鸿蒙PC上安装原版DeepSeek Harness / DSH(让koffi可用,解决硬连接和权限问题)

@Ta 5小时前发布,2小时前修改 88点击

视频链接


  1. 安装 Harmonybrew:https://harmonybrew.atomgit.com/

  2. uname-is-linux 把系统伪装成Linux,避免 koffi 安装报错:

brew install -y ohos-sdk devel-base llvm-gcc-compat cmake uname-is-linux

安装完成后请重新打开终端,执行以下命令验证效果:

export LD_PRELOAD=$HOME/.harmonybrew/opt/uname-is-linux/lib/libuname.so
uname -a

应该会显示Linux而非HarmonyOS

screenshot_20260815_154716.jpg(55.66 KB)

  1. 安装 DeepSeek Harness 到单独的 "$HOME/.npm-global" 目录:
brew install python3 node

npm config set prefix "$HOME/.npm-global"

export LD_PRELOAD=$HOME/.harmonybrew/opt/uname-is-linux/lib/libuname.so
npm install -g @deepseek-ai/dsh --verbose

如果还是在安装koffi的时候报错,请重新打开终端让uname伪装生效。

image.png(0.99 MB)
image.png(1.06 MB)

  1. ohos-sdk附带的binary-sign-tool命令对koffi库进行签名,让koffi能正常加载(不签名会报Permission denied错误):
f="$HOME/.npm-global/lib/node_modules/@deepseek-ai/dsh/node_modules/koffi/build/koffi/openharmony_arm64/koffi.node"; binary-sign-tool sign -inFile "$f" -outFile "$f" -selfSign 1

完整的签名工具教程(包括另一个可以给claude二进制签名的第三方签名工具):
https://hu60.cn/q.php/bbs.topic.107186.html#nav

  1. 解决缺少sharp库的问题:
cd "$HOME/.npm-global/lib/node_modules/@deepseek-ai/dsh"
npm install --no-save --no-package-lock --no-audit --no-fund @img/sharp-wasm32@0.35.3
  1. 解决node启动时缺少--expose-internals参数的问题:
sed -i 's@^#!/usr/bin/env node$@#!'"$HOME"'/.harmonybrew/bin/node --expose-internals@' "$HOME/.npm-global/lib/node_modules/@deepseek-ai/dsh/lib/bin.js"

这条命令是把 $HOME/.npm-global/lib/node_modules/@deepseek-ai/dsh/lib/bin.js 的第一行改成 #!/storage/Users/currentUser/.harmonybrew/bin/node --expose-internals

  1. 修复硬连接创建失败导致的500错误:

本轮运行失败EACCES: permission denied, link '/storage/Users/currentUser/.dsh/sessions/--storage-Users-currentUser-work-wine-WineHua--/session-207ab6ad-2f89-445f-8e60-c11b72a2de56/session.jsonl.zstd.55acf2760149.tmp' -> '/storage/Users/currentUser/.dsh/sessions/--storage-Users-currentUser-work-wine-WineHua--/session-207ab6ad-2f89-445f-8e60-c11b72a2de56/session.jsonl.zstd'

image.png(62.05 KB)

改为在硬连接失败后直接重命名(通过nodejs脚本给源代码打补丁,把下面的代码一次性复制到终端粘贴执行即可):

FILE="$HOME/.npm-global/lib/node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/index.js"
cp "$FILE" "$FILE.bak"
node - "$FILE" <<'NODE'
const fs = require("fs");
const f = process.argv[2];
let s = fs.readFileSync(f, "utf8");

// 1) import 增加 rename
const OLD_IMPORT = 'import { link, mkdir, mkdtemp, open, readFile, readdir, realpath, rm, stat, truncate } from "node:fs/promises";';
const NEW_IMPORT = 'import { link, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, stat, truncate } from "node:fs/promises";';
if (!s.includes(OLD_IMPORT)) { console.error("[1/2] import 行未找到(可能已打过补丁)"); process.exit(0); }
s = s.replace(OLD_IMPORT, NEW_IMPORT);

// 2) link → link 失败时回退 rename(HarmonyOS 禁止硬链接 EACCES/EPERM)
const OLD_LINK = "await link(tmp, finalPath);";
if (!s.includes(OLD_LINK)) { console.error("[2/2] link 语句未找到(可能已打过补丁)"); process.exit(0); }
const NEW_LINK = 'try { await link(tmp, finalPath); } catch (error) { if (error.code !== "EACCES" && error.code !== "EPERM") throw error; await rename(tmp, finalPath); }';
s = s.split(OLD_LINK).join(NEW_LINK);

fs.writeFileSync(f, s);
console.log("patched:", f);
NODE
  1. 解决HMDFS权限问题导致第二次启动时报错:

Error: dsh: plugin tree failed to load: failed to apply loader entry include (cordis:include): failed to apply loader entry credentials (@deepseek-ai/dsh-credentials-local): credentials-local: /storage/Users/currentUser/.dsh/.credentials.yaml is readable beyond its owner (mode 660); run "chmod 600 /storage/Users/currentUser/.dsh/.credentials.yaml" before starting again
Error: credentials-local: /storage/Users/currentUser/.dsh/.credentials.yaml is readable beyond its owner (mode 660); run "chmod 600 /storage/Users/currentUser/.dsh/.credentials.yaml" before starting again

rm -rf ~/.dsh
mkdir /data/storage/el2/base/files/dsh
ln -s /data/storage/el2/base/files/dsh ~/.dsh

/data/storage/el2/base/files是正常的f2fs文件系统,权限可以正常设为660,不过还是不支持硬连接。

  1. 把 dsh 命令链接到 harmonybrew 的 bin 目录,方便后续调用:
ln -s ~/.npm-global/bin/dsh ~/.harmonybrew/bin
  1. 启动 dsh web 服务:
dsh web

image.png(35.4 KB)

然后就可以访问 http://127.0.0.1:3080 进行使用了。

常见问题

  1. DeepSeek Harness 无法执行任何命令

安装 bash 即可:

brew install bash

image.png(47.76 KB)
image.png(530.15 KB)

  1. 海泰浏览器访问 DeepSeek Harness 接口始终返回403错误

海泰浏览器(左)的Origin头不含端口,会导致API返回403错误,目前暂时无法解决。换成海泰极速浏览器(右)就没有这个问题了。

image.png(763.97 KB)

在海泰浏览器里选择“重置设置”也可以解决该问题。

image.png(86.47 KB)

回复列表(0|隐藏机器人聊天)
帖子没有回复
添加新回复
回复需要登录