Introduction

In a host environment like DeepSeek Harness (DSH), agents often need to execute commands in a Windows terminal. The common problem is not “will it call tools”, but rather issues with the commands themselves—such as bash habits, pasted prompts, CRLF pollution, or line continuation errors—which cause tool calls to fail first, wasting a turn on a fix.

Existing solutions usually involve letting the agent execute the failed command directly, or checking manually before execution. powershell-fix is a host-layer plugin for DSH: it provides an agent with a powershell_fix tool that checks and fixes common syntax issues in Windows PowerShell commands before executing the corrected command via the host shell channel. The execution process continues to use the host’s original sandbox, approval, and timeout policies; the plugin itself does not add extra permissions.

What is this

powershell-fix is a DSH host-layer plugin, maintained by GuTianshuo, licensed under MIT, and version 0.1.0 as declared in package.json.

It solves a very specific problem: when commands with bash styles, paste pollution, or line continuation errors enter the Windows PowerShell environment, it checks and fixes them locally before deciding whether to execute. It converges these issues into a single powershell_fix call rather than letting the error command enter the host shell directly.

Core Features

The following introduces several verified capabilities.

Providing the powershell_fix tool

The plugin exposes the powershell_fix tool to the profile. The tool receives the command to be checked, fixed, or executed, and supports call fields such as command, optional shell, optional execute, and optional description.

Fixing syntax pollution in Windows PowerShell commands

The plugin can handle several common types of paste and pre-execution issues:

  • Normalizing CRLF from copy-paste and stray CR characters.
  • Removing shell prompts pasted in.
  • Fixing line continuation issues.
  • Converting bash-style line continuations to PowerShell backtick continuations.
  • Warning for commands that cannot be safely rewritten instead of blindly rewriting them.

Correct PowerShell commands pass through as-is, and the fix logic is idempotent: running the fix again on an already fixed command will not change the command semantics.

Conservative mapping from bash to PowerShell

The plugin maps some common bash commands to PowerShell equivalents; for commands unsuitable for automatic rewriting, it suggests the corresponding PowerShell approach instead of direct replacement.

This “fix if possible, warn if not” strategy is important: it reduces the risk of accidental repairs and preserves space for the agent to continue judging.

Execution via host shell channel

The corrected command is executed via the host DSH’s shell channel. Execution policies use the same sandbox, approval, and timeout policies as the host’s built-in pwsh tool.

In other words, the plugin does not bypass DSH’s host controls and does not add new execution permissions. It only organizes the command into a form closer to executable, and subsequent execution is still constrained by host policies.

Dangerous commands are fixed but not auto-executed

The plugin has built-in execution gatekeeping. For commands that are semantically destructive, even if the command has been fixed, it will refuse automatic execution.

Verified rejection types include:

  • Recursively delete based on target commands.
  • Format-Volume.
  • Clear-Disk.
  • Set-ExecutionPolicy.
  • del /s or del /q.
  • Environment or system persistence write commands.

Commands of this type will not be executed automatically; the plugin will only stay at the fix or warning level.

Supporting dry-run

If you only want to check and fix without executing, you can use dry-run mode:

{
  "command": "<待检查命令>",
  "execute": false
}

You can also turn off automatic execution via the configuration item autoExecute: false.

Installation and Enablement

First, prepare a local plugin directory, for example /path/to/powershell-fix. The following command installs the plugin to the host layer of a specified profile:

dsh plugin --profile web add file:/path/to/powershell-fix

Here, file:/path/to/powershell-fix is the local path installation method, meaning installation from a local directory rather than constructing an install command from a remote repository address.

After installation, restart the harness. After the steps above, every session under this profile can gain the powershell_fix tool.

If you modify the plugin source code later, please note that the local file: dependency may have already copied old lib/*.js. It is recommended to delete the old dependency copy in the profile and then re-run the install command:

# 删除旧副本 in the profile
node_modules/powershell-fix

# 重新安装
dsh plugin --profile web add file:/path/to/powershell-fix

Typical Usage

Below is an illustration of the powershell_fix call structure. command is a required field, while shell, execute, and description are optional:

{
  "command": "<要检查、修复或执行的命令>",
  "shell": "powershell51",
  "execute": true,
  "description": "check and run after fix"
}

If you only want to perform a fix check without executing the command, you can call it like this:

{
  "command": "<要检查或修复的命令>",
  "execute": false,
  "description": "fix-only dry-run"
}

The default value of the autoExecute config is true, and the default value of timeoutMs is 60000. That is to say, by default, after the tool is fixed, it may enter an automatic execution process; however, dangerous commands will still be intercepted by the execution gatekeeping and will not be executed automatically.

Development and Verification

The plugin declares zero runtime dependencies. The peer dependencies are:

{
  "peerDependencies": {
    "@deepseek-ai/dsh-tools": "*",
    "@deepseek-ai/schemastery": "*"
  }
}

These dependencies are resolved from the host side.

You can run the following commands during development:

node --test

This command runs unit tests.

If you want to check the profile directory’s mount and runtime path, you can run:

node acceptance/mount_check.mjs <profile_web_dir>

Where <profile_web_dir> needs to be replaced with the actual profile directory.

If you want to perform a real engine execution check, you can run:

node acceptance/real_pwsh_e2e.mjs

Applicable Scenarios and Notes

It is suitable for the following scenarios:

  • Using DSH to execute PowerShell commands on Windows.
  • Agents frequently paste bash-style commands into the terminal.
  • Commands often fail due to CRLF, prompts, line continuations, or quote issues.
  • Want to check and fix first, then enter the host execution policy.

A few points need attention:

  • The plugin does not add extra permissions.
  • Command execution still goes through the host shell channel and is constrained by the host sandbox, approval, and timeout policies.
  • Dangerous commands will be intercepted by the execution gatekeeping and will not be executed automatically.
  • autoExecute defaults to true. If you only want to check without executing, you should use execute: false or autoExecute: false.
  • It is recommended to check the source code and license before installation. The current repository license is MIT.

Links

GitHub Repository:

https://github.com/GuTianshuo/powershell-fix