Preface

The core design philosophy of DeepSeek Harness is “Everything Is a Plugin.” In agent development, displaying locally generated images usually requires manually opening file paths or going through a cumbersome attachment upload process. The img-preview plugin registers a tool and a loopback route, enabling AI to render local image files directly in the chat window.

Plugin Introduction

img-preview is a DeepSeek Harness plugin maintained by user dhb861832993-star and licensed under the MIT License. It provides inline local image preview capabilities for DSH clients, supports PNG/JPG/WebP/GIF/AVIF/BMP/SVG/ICO/TGA formats, and includes standalone image viewer interactions.

Core Features

  1. Inline Rendering and Fence Format
    The plugin detects the ```img fence and renders it as an inline image. It supports single-image and multi-image grid display, as well as optional titles.

  2. Tool Integration
    After installation, the model automatically obtains the img_serve tool. This tool is used to validate image paths and issue accessible URLs.

  3. Loopback File Routing
    The plugin registers the /plugins/img-preview/files route; the host serves image data to the browser through this route. The browser cannot read the local disk directly and must use this route.

  4. Path and Format Validation
    Only paths within the workspace root directory are allowed, preventing directory traversal. Only the png/jpg/jpeg/webp/gif/avif/bmp/svg/ico/tga extensions are allowed; files larger than 128 MiB are rejected.

  5. Special Format Handling
    TGA files are automatically decoded and transcoded to PNG on the host side, then rendered by the browser. SVG scripts do not execute when rendered via <img>.

  6. Standalone Viewer
    Double-clicking a thumbnail opens a full-screen overlay viewer. It supports wheel zooming (5%–2000%, centered on the cursor), drag panning, and double-clicking to toggle between 100% and 2.5x. Toolbar actions include Fit to Window, 100%, Original, and Close.

Installation and Enablement

Use the official installation command to add the plugin:

dsh plugin --profile web add github:dhb861832993-star/img-preview

After installation, restart the dsh web service. The plugin will automatically inject usage instructions and take effect in new sessions.

Typical Usage

  1. Tool Call
    The agent needs to first call the img_serve tool to generate an accessible URL.
   # 工具
   img_serve(path: "H:/工作-deepseek/dm_output/xxx.png")
  1. Fence Format
    Use the ```img fence in your reply, passing the path and an optional label.
```img
   {"path":"H:/工作-deepseek/dm_output/xxx.png","label":"可选标题"}
3. **Multi-Image Display**
```text
```img
   {"images":[{"path":"a.png"},{"path":"b.png","label":"B"}]}

`` Note: The plugin automatically normalizes backslashes (`) in paths to forward slashes (/) to ensure valid JSON.

Security and Limitations

  • Permission Scope: The plugin runs with the permissions of the current DSH process. It allows only paths inside the workspace root directory, and prevents directory traversal attacks through path normalization and prefix validation.
  • Resource Limits: File size is limited to 128 MiB; larger files are rejected. Only specific image extensions are supported.
  • Rendering Isolation: SVG files are rendered using the <img> tag, and the browser blocks script execution within them, which is relatively safe.

Summary

img-preview solves the inconvenience of displaying local images in the DSH environment. By combining the img_serve tool with the ```img fence, developers can have the model display generated images immediately in the conversation, improving the interactive experience.