DSH’s built-in DiffBlock renders unchanged lines both in the removal section (red -) and the addition section (green +) when displaying file differences, causing visual redundancy. When only one line is modified, this repetition can mix up the context and make the actual change hard to identify at a glance.

This plugin takes over DSH browser’s edit / write tool cards, uses a near-linear line-level diff algorithm, renders only the actually changed lines, and supports inline character highlighting, thereby eliminating duplicate display.

Basic Information

  • Name: dsh-edit-diff
  • Maintainer: better-er
  • Category: Workflow
  • License: MIT
  • Positioning: DSH deduplicated diff display plugin

Core Features

The plugin provides filtering and highlighted display of difference lines, with core capabilities as follows:

  1. Only diff lines: Identical lines are not rendered; only the actual removed lines (red -) and added lines (green +) are displayed, eliminating duplication.
  2. Inline character highlighting: When the number of removed and added lines is equal, a character-level diff is performed on replacement pairs, using an underline within the line to mark the truly changed characters.
  3. Near-linear algorithm: It first shrinks common prefixes and suffixes linearly, then runs Myers diff only on the small intermediate diff band. Complexity is proportional to the amount of differences, keeping it smooth even for very large files.
  4. Default collapsed and secondary folding: The card shows only a one-line summary by default; the diff body is shown only after expansion. After expansion, if changed lines exceed 14 lines, they are folded into “head + ⋯ expand remaining N changed lines + tail”.
  5. Native-looking alignment: It uses the --dsw-* theme variables from the built-in DiffBlock/ToolRow to maintain visual consistency.
  6. Copy and statistics: The copied content includes only diff lines prefixed with -/+; the bottom displays change statistics └ +A -R · N file(s).
  7. Takeover scope: Supports dual takeover of edit / write, covering new-file scenarios. It is also compatible with run_code subcalls in PTC mode.
  8. Takeover of other tools: Through extraTools configuration, it takes over other tools (such as edit_remote / write_remote of dsh-remote-file-system).

Installation and Enablement

Run the following commands within DSH to install it. Both installation methods are automatically mounted and become effective after restarting DSH web, without manually editing configuration.

Install from GitHub (recommended, automatic build):

dsh plugin --profile web add github:better-er/dsh-edit-diff

Install from npm (uses prebuilt artifacts):

dsh plugin --profile web add dsh-edit-diff

Configuration

The plugin uses extraTools to take over other tools besides edit / write. By default, it takes over edit_remote and write_remote from dsh-remote-file-system.

Default Takeover Configuration

The plugin’s bundled cordis.patch.yml provides the default takeover configuration:

- insert:
    - id: dsh-edit-diff
      name: dsh-edit-diff
      config:
        extraTools:
          - name: edit_remote
          - name: write_remote

Custom Takeover Configuration

If you need to take over tools with different parameter names, you can override the configuration by id in the profile’s cordis.patch.yml. Each extraTool must specify name, and optionally pathKey, oldKey, newKey, and contentKey.

- id: dsh-edit-diff
  config:
    extraTools:
      - name: some_tool
        pathKey: target
        oldKey: before
        newKey: after
        contentKey: body

Determination Rules

The rendering logic is determined by parameters: if both old text and new text are present, it is rendered as an edit type; otherwise, if the full file content is present, it is rendered as a write type.

Applicable Scenarios

  • edit / write workflows that require clearly viewing code or text modifications.
  • PTC mode where run_code is used for code editing and diff display is needed.
  • Scenarios that handle remote file changes and need to display differences (dsh-remote-file-system is taken over by default).

The plugin is mounted as a standard plugin, passes configuration to the browser side through the settings namespace, and all rendering is completed in the browser.