dsh-block-hanging-commands: Intercepting hanging commands before Shell execution

Introduction

When having agents run Shell commands in DeepSeek Harness (DSH), a common class of failure occurs: the model issues git commit without the -m flag, or runs npm run dev or python3 without any subsequent parameters. The command waits for keyboard input, but no one provides it; the tool typically times out, this round yields almost no useful feedback, and the next round may attempt the same hanging call again.

Manually emphasizing “no interactive commands” in the prompt can mitigate some of this, but cannot cover combinations such as pipelines, && chains, and wrapped commands. Below is an introduction to the community plugin dsh-block-hanging-commands (maintained by acus9345), which performs static checks before a command is actually executed, directly rejecting calls that would wait for input or fail to exit for a long time, and returns the reason along with alternative syntax to the model.

What Is This

dsh-block-hanging-commands is a plugin for DeepSeek Harness, categorized as admin-security. During the tools/pre-execute stage, it reads the Shell command about to be executed, returns deny with explanatory text for calls matching its rules, without rewriting the command or spawning a Shell; the model can then switch to a non-interactive approach in the same step based on the hint.

See the GitHub repository for source code and documentation, and the community directory page: skillhub.cn/plugins/acus9345/dsh-block-hanging-commands. This directory is an independent community site and has no official affiliation with DeepSeek / High-Flyer.

Core Features

Rule Coverage

The plugin performs lexical-level parsing of commands (without spawning a Shell) and recognizes common wrappers (sudo, env, nohup, npx, bash -c, etc.) as well as pipelines, &&, heredocs, and redirections. The rules and examples listed in the README are as follows.

Rule Typical Command Suggested Alternative
editor vim, nano, code --wait Use the edit tool or sed -i
git-editor git commit without -m, git tag -a git commit -m "..." or --no-edit
git-interactive git rebase -i, git add -p Non-interactive rebase / git add <path>
repl python, node, psql mydb -c "...", a script file, or a heredoc
server npm run dev, vite, next dev run_in_background: true or timeout
watch jest --watch, tsc -w Drop watch, run once
follow tail -f, kubectl logs -f tail -n 200, --since, etc.
remote-shell ssh host without a remote command Append a remote command; -o BatchMode=yes
container-tty docker run -it, kubectl exec -it Remove -it
tui htop, lazygit Batch form (e.g., top -bn1)
prompt / login npm init without -y, gh auth login Non-interactive flags or confirm with the user
pager, tty-prompt less, sudo requiring a password Enable the relevant rules only under a PTY Shell

When blocked, the model receives feedback similar to the following (excerpted from the README):

dsh-block-hanging-commands stopped `git commit` before it ran, because `git commit`
without a message opens an editor, so the tool call would just sit there until it timed out.
Instead: pass the message: `git commit -m "<message>"` (or `--no-edit` when amending).
(rule: git-editor)

Allowlisting and Exceptions

To reduce false positives, the following cases are allowed: psql -c "select 1", node script.js, git commit -F msg.txt, ssh host uptime, --help / --version, etc. echo q | python3 and python3 < script.py are not blocked because input is already available. timeout 30 npm run dev, dev servers launched with run_in_background: true, or calls where the Shell tool’s own timeoutMs bounds the duration are also allowed. When executed via PowerShell (pwsh) on Windows, the plugin likewise handles npm.cmd and executables in path form.

Installation and Activation

DSH maintains plugin lists per profile: web (dsh web browser UI), headless (scripts and CI), and acp (editor integration). Install it separately on each profile you plan to use.

Taking the web profile as an example:

dsh plugin --profile web add dsh-block-hanging-commands

The plugin ships with a patch layer and takes effect immediately upon installation, with no additional toggle required. To uninstall:

dsh plugin --profile web remove dsh-block-hanging-commands

Configuration

You can open dsh-block-hanging-commands under Plugins in the DSH sidebar, modify it, click Save, and the next tool call will reflect the changes without needing a restart.

You can also write to ~/.dsh/profiles/<profile>/cordis.patch.yml, or the global ~/.dsh/cordis.patch.yml:

- id: block-hanging-commands
  config:
    mode: deny             # or ask: prompt for confirmation instead of denying outright
    tools: [bash, pwsh]    # Shell tool names to check (pwsh on Windows)
    pty: false             # Whether the Shell runs on a PTY (e.g., dsh-tool-bash-persistent)
    disabledRules: []      # e.g., [server] to allow starting a dev server
    allowPatterns: []      # Regular-expression allowlist, e.g., ['^make serve$']

Keys left unset retain their default values. When pty is false, rules that depend on a terminal such as less and sudo are not enabled, avoiding false positives in non-PTY environments.

Use Cases and Caveats

Suitable for teams or individuals who frequently have agents execute Shell commands in DSH and want to reduce “entire-round hangs”. The plugin runs with the current dsh process permissions; before installing, it is recommended to review the source code and the MIT license to confirm the behavior matches your security policy.

If you genuinely need the model to start a dev server or use watch mode, you can relax the rules via disabledRules or allowPatterns; mode: ask routes through manual confirmation before blocking.

Conclusion

dsh-block-hanging-commands moves “Shell commands that would hang” from the execution stage upfront into explainable rejections with alternative suggestions, reducing idle spinning on timeouts. For more information, see the community directory page and GitHub.

羽毛球分组比赛记分
小程序二维码

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

Xiaoye