Chuyển đến nội dung chính

dsh-rtk-rewrite

Đã xác minh

dsh-rtk-rewrite · v0.1.0 · MIT

DSH (DeepSeek Harness) plugin that auto-rewrites pwsh tool commands to their rtk equivalents before execution — cutting shell output tokens by 42-90%. Commands with no rtk equivalent pass through unchanged.

Cài đặt

dsh plugin add dsh-rtk-rewrite

Xác nhận layer đã áp bằng dsh --profile default --dump-config — xem hướng dẫn cài plugin.

Mã nguồn

Phát hành lên npm mà không có repository công khai. Hãy kiểm tra nội dung package trước khi cài.

Thẻ

Tác giả

Readme

dsh-rtk-rewrite

DSH (DeepSeek Harness) 插件:自动把 pwsh 工具的命令改写为 rtk 等价命令,削减 shell 输出 token 42-90%

你发: git status
dsh 执行: rtk git status   ← 插件自动改写
输出: * master...origin/master      (极简,省 42%)
      ?? plans/xxx.md
  • 不替换 dsh 基础工具(pwsh/bash 原样保留)
  • 不阻塞任何命令——rtk 缺失/不支持/超时一律原样放行
  • 不绕 sandbox/approval 栈——只改命令字符串,走原执行管线

原理

dsh 的 tools/pre-execute 瀑布(官方扩展点)携带可改写的原始参数。插件在此拦截:

tools/pre-execute ──→ spawnSync("rtk.exe rewrite <cmd>")
                      ├─ stdout 以 "rtk " 开头 → 替换 exec.arguments.command
                      └─ 否则 → 原样放行

⚠️ 为什么不用 tools/execute?它的契约是 "wrappers may change only exec.signal, while call identity remains immutable"——参数在该阶段已冻结, 不可改写。tools/pre-execute 是唯一合法的命令改写点(已实测验证)。

安装

# 1. 安装 rtk(Apache-2.0,独立项目,不捆绑在本包内)
#    Windows: 下载官方 release 或
curl -L https://github.com/rtk-ai/rtk/releases/latest/download/rtk-x86_64-pc-windows-msvc.zip -o rtk.zip
#    或走 npm 脚本:npm run install-rtk --prefix <本包路径>
#    验证: rtk --version

# 2. 安装本插件到 dsh web profile
dsh plugin --profile web add "link:<本包路径>"
#    或从 npm: dsh plugin --profile web add dsh-rtk-rewrite

# 3. 重启 dsh
#    桌面 启动dsh.bat 或 dsh web --port 3080

配置

# ~/.dsh/profiles/web/cordis.patch.yml 或插件 cordis.patch.yml
- insert:
    - id: dsh-rtk-rewrite
      name: 'dsh-rtk-rewrite'
      config:
        enabled: true              # false 时插件完全惰性
        rtkPath: 'C:\...\rtk.exe'  # 可选;缺省时 PATH 探测 → 常见安装目录

rtk 解析优先级:config.rtkPathPATH 查找 → 常见安装目录(~/.local/bin/rtk 等)。

可改写的命令

git / gh / glab / ls / cat / type / find / grep / rg / python / pytest / npm / pnpm / yarn / npx / wc / tree / psql / docker / kubectl / dotnet / tsc / vitest / jest / go / cargo / curl / wget / env / diff / log / err / test / json / summary / smart / aws / oc

永不改写cd / echo / exit / set / pushd / popd / clear / cls(已很廉价或语义特殊)。

判断标准是 rtk.exe rewrite <cmd> 的 stdout:非空且以 rtk 开头 → 改写;否则放行。

平台

  • Windows:目标 pwsh 工具(dsh 在 win32 用 pwsh;bash 工具被禁用)
  • Linux/macOS:目标 bash 工具(代码已含 exec.name === 'bash' 分支,未实测,欢迎 PR)

设计要点(踩坑记录)

事实
改写点 必须 tools/pre-executetools/execute 参数冻结
退出码 rtk 在 Windows exit 1/3 都可能是成功——看 stdout
路径转义 配置里反斜杠要双写(\\)或 String.raw
&& Windows PowerShell 不认 &&,改写结果里的 &&;
插件沙箱 动态插件(cordis_define)里 ctx.logger 被 guard 拦截;本插件是静态插件(host 进程),无此限制

License

MIT。rtk 本体是独立的 Apache-2.0 项目(github.com/rtk-ai/rtk),不随本包分发。