dsh-pwsh-quoting-guard: Resolving PowerShell Command String Quote Escaping Issues

Introduction

When using DSH (DeepSeek Harness) in Windows environments, models often get stuck on quote escaping when writing PowerShell commands. Paths containing spaces, Chinese characters, special symbols (such as $, %), or nested quotes can easily cause command execution to fail or produce unexpected behavior. The dsh-pwsh-quoting-guard plugin introduces a structured data-passing mechanism to remove the escaping burden from the “command string” layer, ensuring data is passed accurately.

Plugin Overview

Name: dsh-pwsh-quoting-guard
Maintainer: fengbai2233
Category: admin-security
License: MIT

This plugin provides two tools: pwsh_script and run_argv. They pass parameters through structured arrays to avoid complex quote escaping performed by the model, while pinning UTF-8 encoding to ensure stable behavior under executors such as Windows PowerShell 5.1.

Installation and Enablement

Use the following command to add the plugin to the specified profile:

dsh plugin --profile web add dsh-pwsh-quoting-guard

After installation, restart dsh web so the plugin combination takes effect.

Tool Description

The plugin provides two core tools for different scenarios.

pwsh_script

Passes data structurally through $DSH_ARGS, delivering the script body as a single element to avoid quote escaping.
* Parameters:
* script (string, required): PowerShell script body.
* args (string[]): Parameter list, bound sequentially starting at $DSH_ARGS[0].
* Features: Zero runtime dependencies, pins UTF-8 encoding, and supports the cwd parameter.

run_argv

Passes arguments directly as argv, completely bypassing shell parsing. It is suitable for executing native programs with faithful parameter preservation.
* Parameters:
* program (string, required): Executable file name or absolute path.
* args (string[]): Argument vector.
* cwd (string): Working directory; defaults to the session workspace.

Usage Examples

Example 1: Read a path containing special characters

{
  "script": "(Get-Content -LiteralPath $DSH_ARGS[0] -Raw).Trim()",
  "args": ["E:\\deepseekwork\\插件\\.dsh-tmp\\$100 %TEMP% it's dir\\sample file.txt"]
}

Example 2: Run node in a specified directory and preserve arguments faithfully

{
  "program": "node",
  "args": ["-e", "console.log(process.cwd(), process.argv.slice(1))", "a\\\"b'c"],
  "cwd": "E:\\deepseekwork\\插件\\.dsh-tmp\\$100 %TEMP% it's dir"
}

Working Principle

  1. Structured isolation: pwsh_script passes the script body as a single argv element to PowerShell via -Command; data is delivered through the $DSH_ARGS array, so the model does not need to worry about escaping.
  2. Shell-free: run_argv directly invokes ctx.subprocess.spawn; arguments are not parsed or expanded by a shell, ensuring they are passed in their original form.
  3. Environment alignment: Injects environment variables such as NO_COLOR and PAGER, and handles sandbox permissions to ensure output formatting remains consistent with standard tools.

Known Limitations

  • No background tasks: pwsh_script does not support run_in_background. For long-running tasks, use the official pwsh tool instead.
  • Line number offset: If an argument value contains newline characters, script line numbers may shift.
  • Prompt segment uniqueness: Prompt segment names must be unique within the same layer to avoid plugin tree loading failure caused by duplicate names.
  • Hard dependency: The inject declaration is hard; ['subprocess', 'tools'] must be declared to access the related context.

Troubleshooting

  • Tool not visible: Check whether dsh web has been restarted.
  • Startup failure: If the error says cannot get property "tools" without inject, check whether inject is declared correctly.
  • Duplicate name error: Check whether the plugin is installed in both the profile and preset.

Conclusion

dsh-pwsh-quoting-guard solves the most troublesome escaping problem in PowerShell command-line argument passing on Windows through structured tool interfaces. For scenarios requiring complex path handling or native program execution, it significantly reduces retries and token waste caused by quoting errors.

  • GitHub: https://github.com/fengbai2233/dsh-pwsh-quoting-guard
  • Catalog: https://www.skillhub.cn/plugins/fengbai2233/dsh-pwsh-quoting-guard
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye