dsh-wsl
开发工具 活跃维护

dsh-wsl

XINY11451/dsh-wsl

轻量级WSL工具插件,支持AI代理直接调用wsl.exe执行Linux命令,无需手写shell脚本或PowerShell包装器,简化模型侧Linux操作流程,开箱即用。

1
Stars 标星
0
Forks 分支
1
Watchers 关注
0
Open Issues
JavaScript
主要语言
MIT
开源协议
102 KB
仓库大小
3 个月前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:XINY11451/dsh-wsl
git clone https://github.com/XINY11451/dsh-wsl.git
git clone git@github.com:XINY11451/dsh-wsl.git
README.md main

dsh-wsl

English | 简体中文

A model-facing WSL tool plugin for DeepSeek Harness (DSH). It lets an agent run Linux commands through wsl.exe directly — no hand-written .sh scripts or pwsh wrappers.

Tools

The plugin registers three tools:

Tool Purpose
wsl Run a Linux command and return stdout/stderr with exit-code markers.
wsl-path Convert between Windows and WSL paths via wslpath.
wsl-env Summarize the WSL environment (distros, kernel, cpu, mem, disk).

wsl

Runs:

wsl.exe -d <distro> -e bash -lc "cd <workdir> && <command>"

and returns stdout/stderr with [exit code: N] / [killed by signal: ...] /
[output truncated] markers.

wsl-path

Converts a path in either direction: C:\Users\me\a.txt -> /mnt/c/Users/me/a.txt
or /home/me/a.txt -> \\wsl.localhost\Ubuntu-22.04\home\me\a.txt. Direction is
auto-detected from the path, or forced with direction: 'win' | 'linux'.

wsl-env

No arguments. Returns the distribution list, default distro, kernel, CPU count,
memory and disk usage so an agent knows what it is running on.

Install

  1. Add the package to your DSH profile (profiles/<profile>/package.json):

    { "dependencies": { "dsh-wsl": "file:<path-to-this-repo>" } }

    or run dsh plugin add --profile <profile> file:<path-to-this-repo>.

  2. Add a tool-wsl row to an agent preset's agent.cordis.yml:

    - id: tool-wsl
     name: 'dsh-wsl'
  3. Restart DSH.

wsl parameters

Param Required Type Notes
command yes string Linux command to execute
description yes string short UI label
workdir no string WSL/Linux path, default ~
timeoutMs no number timeout in milliseconds
distro no string WSL distribution name, default Ubuntu-22.04
env no object extra environment variables to export
allowDangerous no boolean set true to run destructive commands

Notes

  • Each call runs in a fresh bash -lc shell — no cwd/variables/functions persist between calls.
  • The default distro is Ubuntu-22.04; override it per call with the distro argument or globally with the DSH_WSL_DISTRO environment variable. Edit DEFAULT_DISTRO in index.js to change the fallback.
  • Windows paths (C:\...) in command and workdir are translated to /mnt/c/... automatically.
  • Destructive commands (rm -rf, dd onto a block device, mkfs, shutdown, fork bombs, …) are refused unless the call passes allowDangerous: true.
  • Uses wsl.exe -e (--exec) so quoting and $VAR expansion behave like a normal shell; the default -- pass-through mangles single quotes and variables.

Install from the plugin list

The package declares a dsh.bundle manifest (see package.json), so once the
repository is listed it can be installed by name, e.g. dsh plugin add dsh-wsl,
and storefronts will offer it for one-click install. Installing from a local
path (file:) as shown above keeps working either way.

How it works

The plugin is a cordis module that injects the host-plane tools and
subprocess registries:

  • apply() registers three tools, each with a JSON-schema parameter definition,
    an output schema, a render hook and an async execute.
  • execute() spawns wsl.exe -d <distro> -e bash -lc "<cd workdir && command>"
    through the host subprocess service, with stdin ignored, stdout/stderr
    capped at 64 KiB (spilling to disk up to 64 MiB), a 3 s grace period after
    abort, and an optional timeoutMs that aborts the call.
  • env entries are exported at the front of the command so they reach the
    Linux side reliably; Windows drive paths are rewritten to /mnt/... before
    the command is built.
  • Output is returned as { exitCode, signal, stdout, stderr, truncated };
    the render hook formats it into text with [exit code: N] / [killed by signal: ...] / [output truncated] markers.
  • A destructive-command guard runs on the final command string before dispatch
    and refuses matched patterns unless allowDangerous is set.

The plugin publishes no services of its own, so it sits loose in an agent
preset without a realm.

Development

The plugin is plain ESM with no build step or runtime dependencies outside the
DSH host plane. Iterate by pointing a profile dependency at the checkout:

{ "dependencies": { "dsh-wsl": "file:/path/to/dsh-wsl" } }

then restart DSH and exercise the tools from a session that uses a preset
containing the tool-wsl row.

Customization points live at the top of index.js: DEFAULT_DISTRO,
DEFAULT_WORKDIR, the output caps, the grace period and the destructive-pattern
list.

Listing

The repository carries the dsh-plugin topic and is listed under the wsl
category of the awesome-dsh-plugin community list.