Skip to main content
S

dsh-python-tools

saulgoodman174/dsh-python-tools

Run trusted Python scripts in the workspace, read text from searchable PDFs, and export DOCX to PDF through Microsoft Word on Windows.

Install

dsh plugin --profile web add github:saulgoodman174/dsh-python-tools

README

dsh-python-tools

Awesome DSH Plugin

dsh-python-tools turns three everyday desktop chores into host tools the agent can call directly.

python_run executes a script you keep in the workspace's scripts directory. Arguments are passed as an array rather than a shell string, so paths with spaces and non-ASCII characters survive untouched, and every call runs under a timeout with cancellation.

python_pdf_text reads a searchable PDF through pypdf and returns the page count plus the extracted text, truncated to a configurable character limit so a 300-page document cannot flood the conversation.

python_docx_to_pdf exports a DOCX to PDF using the Microsoft Word already installed on Windows. It refreshes fields and the first table of contents only when you ask for it, and it never modifies the source document: the plugin reports the page count and the output path instead.

Interpreter path, scripts directory, an optional allow-list, the pypdf location, timeout, and output limit are all set on the plugin row. Failures come back as stable codes — FILE_NOT_FOUND, SCRIPT_NOT_ALLOWED, TIMEOUT, ABORTED, MISSING_DEPENDENCY, UNSUPPORTED_PLATFORM — so the agent can correct itself instead of guessing what went wrong.

Installation

Choose the route that matches your DSH profile.

  1. Plugin market (dshmarket). Open the Plugins page, pick the Plugin Market tab, search dsh-python-tools, and install it in one click. The same catalog is readable as a market index at https://cdn.jsdelivr.net/npm/dsh-plugin-catalog/index.json (Plugins → Discover → Index sources).
  2. DSH Desktop, local checkout. Clone the repository. Open Settings → Plugins → Add plugin → Install third-party plugin (设置 → 插件 → 添加插件 → 安装第三方插件). Enter the directory containing package.json, then enable the dsh-python-tools component. Use this route for the Electron-managed desktop profile.
  3. CLI-managed web profile, local checkout. Run dsh plugin --profile web add "<workspace>/dsh-python-tools". Replace <workspace> with the absolute parent directory of the checkout. Restart dsh web and enable the component under Settings → Plugins.
  4. CLI-managed web profile, published npm package. After publication, run dsh plugin --profile web add dsh-python-tools. Restart dsh web and enable the component. If the release uses a scope, supply its full published package name.

Platform support

The plugin requires Node.js ^22.19 || >=24 and a host providing the @deepseek-ai/schemastery peer (^3.18.5).

ToolPlatformRequirements
python_runWindows, macOS, LinuxPython and the dependencies of the selected script
python_pdf_textWindows, macOS, LinuxPython and pypdf
python_docx_to_pdfWindowsWindows PowerShell and desktop Microsoft Word available through COM to the account running DSH

Install pypdf into the interpreter configured by pythonPath. For the default interpreter:

python -m pip install pypdf

Alternatively keep it out of the interpreter: run python -m pip install --target .pylibs pypdf in the session workspace. The plugin appends an existing <workspace>/.pylibs to PYTHONPATH when pylibs is empty, and appends the configured directory otherwise.

The Word converter does not require Python. The two document tools find their helpers relative to the installed plugin.

Configuration

KeyDefaultBehavior and security implications
pythonPathpythonCommand found on PATH, or a path to a trusted interpreter. A relative path containing a directory separator resolves against the session workspace.
scriptsDirtoolsDirectory used by python_run. The default resolves to <workspace>/tools. Grant write access only to people trusted to run code under the DSH account.
allowedScripts[]An empty array trusts all directly contained .py files in scriptsDir, including files added later. A nonempty list restricts execution to exact filenames.
pylibs""Optional directory appended to the Python child process's PYTHONPATH. When empty, an existing <workspace>/.pylibs directory is used automatically. Its modules can execute code when imported, so use a trusted directory.
timeoutMs120000Per-command time limit in milliseconds. Accepts integers from 1 to 600000.
outputLimit8000Maximum Unicode code points returned per output stream, or in extracted PDF text. Temporary files can grow beyond this limit.
refreshFieldsfalseWhen true, python_docx_to_pdf updates document fields and the first table of contents before exporting. Refreshing can reflow pagination, so the PDF may differ from a direct Word export.

Workspace-relative paths use exec.agent.session.header.cwd. Direct callers should supply an absolute session cwd. Without one, the plugin falls back to the process working directory.

Python receives arguments as individual strings. An allowed script runs with the child process's filesystem and network permissions. Anyone who can replace the script can change its behavior. For example, to expose only the page-count example, copy examples/pdf_pages.py into <workspace>/tools and set allowedScripts to ["pdf_pages.py"].

Tools

Replace <workspace> in these examples with an absolute path. In JSON, escape Windows backslashes or use forward slashes.

python_run

Run the page-count example after copying it into scriptsDir and installing pypdf.

{"script":"pdf_pages.py","args":["<workspace>/sample.pdf"]}

Read stdout for the script's result. The response also reports script, command, exit_code, stderr, duration_ms, timed_out, and truncated after process completion.

Example failure:

{"ok":false,"code":"SCRIPT_NOT_ALLOWED","message":"Select an allowed .py filename directly inside scriptsDir."}

python_pdf_text

{"path":"<workspace>/sample.pdf"}

Returns pages, text, duration_ms, and truncated. Page markers separate the text. A scanned page without a text layer can have an empty body. The tool does not perform OCR.

Example failure when pypdf is unavailable:

{
  "ok": false,
  "code": "MISSING_DEPENDENCY",
  "message": "Install pypdf with the configured interpreter. For the default interpreter run: python -m pip install pypdf.",
  "install_args": ["python", "-m", "pip", "install", "pypdf"],
  "stderr": "Cannot import pypdf: No module named 'pypdf'\n"
}

python_docx_to_pdf

{"path":"<workspace>/report.docx","out":"<workspace>/report-final.pdf"}

Omit out to create report.pdf beside report.docx. The output directory must exist. Word opens the document in the background, exports a PDF, and leaves the source DOCX untouched. Set refreshFields to true to update fields and the first table of contents before exporting, which can reflow pagination. An existing destination PDF is replaced upon successful export.

The result includes pdf, pages, stdout, stderr, and duration_ms. Starting Word and repaginating a document can take several seconds.

Example failure outside Windows:

{"ok":false,"code":"UNSUPPORTED_PLATFORM","message":"DOCX export requires Windows and desktop Microsoft Word."}

Helper protocols

If you replace a bundled helper, preserve its command-line and output protocol.

  • runtime/pdf_text.py INPUT.pdf writes the decimal page count alone on the first stdout line. The body begins on the second line. Page headings are part of the body. Warnings and diagnostics go to stderr. Exit 0 means success, 43 means importing pypdf failed, and 1 means extraction failed. The plugin checks the exit status before parsing stdout. examples/pdf_text.py implements the same protocol and can be run directly with python examples/pdf_text.py x.pdf.
  • runtime/docx_to_pdf.ps1 -Docx INPUT.docx -Pdf OUTPUT.pdf exits 0 on success. Its last two stdout lines must be exactly pages=N and pdf ok, with no trailing spaces. The parser accepts LF or CRLF and one final line terminator. Exit 43 means the helper could not activate Word through COM. Other conversion failures exit 1 and write details to stderr. A missing PowerShell executable is detected by the plugin before the helper starts.
  • Exit 43 has dependency semantics only for these bundled helpers. A user script selected through python_run may define its own exit codes; a nonzero result is reported as SCRIPT_FAILED.

Error codes

CodeMeaningHow to fix it
INVALID_ARGUMENTThe supplied fields, types, filename extension, or path form are invalid.Follow the tool example and use absolute document paths.
SCRIPT_NOT_ALLOWEDThe requested filename violates the script directory or allowlist rules.Use the actual .py filename directly inside scriptsDir and check allowedScripts.
FILE_NOT_FOUNDA document, user script, or scripts directory could not be found.Check the session workspace and the resolved path.
FILE_ACCESS_FAILEDThe plugin could not inspect a required filesystem entry.Check filesystem permissions and host policy for the DSH account.
TOOL_NOT_FOUNDThe executable or the specified process working directory could not be located.Verify the workspace exists and check pythonPath or Windows PowerShell.
MISSING_DEPENDENCYThe PDF helper could not import pypdf, or the Word helper could not activate Word COM.Run the returned install_args for Python. For Word, install or repair desktop Word and verify COM access under the DSH account.
UNSUPPORTED_PLATFORMWord conversion was requested outside Windows.Run this tool on a Windows host with desktop Word.
SPAWN_FAILEDProcess launch or temporary output handling failed.Check executable permissions and access to the system temporary directory.
SCRIPT_FAILEDThe started process failed during execution.Read stderr; check script arguments, document validity, output access, and script-specific dependencies.
INVALID_OUTPUTA successful helper returned malformed page metadata or completion markers.Restore the bundled helper or correct its output protocol.
TIMEOUTExecution exceeded timeoutMs.Inspect blocked dialogs or slow inputs, then adjust timeoutMs if appropriate.
ABORTEDThe caller cancelled the command.Inspect any output already produced before retrying.

Troubleshooting

Component fails to load. Look for dsh-python-tools: invalid config: in the component error details or host log. The rest of the message identifies the invalid setting. For example, timeoutMs must be an integer between 1 and 600000. Correct the value and reload the component. Host-side schema validation may also reject a value before apply runs.

Python works in a terminal but cannot import pypdf in DSH. Check the interpreter in the returned install_args. Use that executable to install the package. If using a virtual environment, set pythonPath to its interpreter.

Word starts but conversion fails. Open the source document under the DSH account and check for Protected View, password prompts, read-only access, or a locked destination. The helper needs write access to the output directory.

A conversion was cancelled or timed out. The executor redirects output into temporary files, sends SIGTERM to the immediate child, and 1.5 seconds later terminates the whole process tree when the host permits it: taskkill /T /F on Windows and a process-group kill elsewhere. A host that forbids process enumeration and tree termination can leave the Word instance running after a forced kill; inspect Word and the destination before retrying.

The tests fail with spawn EPERM. Some hosts restrict child-process pipes. Run node test.mjs directly instead of npm test; the assertions are the same.

Tests

From a repository checkout with Node.js, Python, and the declared peer available:

npm install
npm test

The automated tests use a temporary script directory and a registration fixture. They do not require a running DSH host, Microsoft Word, or an installed copy of pypdf. Set PYTHON to a Python executable if python is not on PATH. Real Word conversion and PDF extraction require separate integration checks with the external software installed.

License

MIT. See LICENSE.

Related plugins