When using DeepSeek Harness for large-scale project refactoring, calling the Write tool directly often leads to incomplete refactoring due to omitted instructions or excessive simplification. To speed up refactoring, save tokens, and migrate modules while preserving source line contents, a more fine-grained line operation capability is needed. The following introduces kezan31/dsh-copy-tool.
This is an enhanced line-selection copying plugin for DeepSeek Harness. The plugin is maintained by kezan31 and aims to address the limitations of using the basic Write tool directly by precisely controlling line ranges to improve the accuracy of code migration and refactoring.
Core Features¶
- Line selection and mapping: Supports selecting single lines or line ranges using 1-based line numbers and copies their contents to the corresponding
target_lines. - Flexible array syntax: The
linesandtarget_linesparameters support mixed array formats, such as[[633, 889]]or[633, [640, 645], 700]. - Indentation handling: Automatically removes the common indentation of selected non-empty lines in the source file and adds 4-space indentation based on the explicit
indentlevel. - Diff preview: Use the
dry_runparameter to preview a bounded unified diff, then execute the changes after confirmation. - Atomic file operations: Use
writeTextto atomically create new files, or useeditTextto atomically edit existing files. - Content preservation: During editing, unselected content and the file system’s native line endings are preserved.
- Path and permissions: Path resolution is based on the current session workspace and follows its sandbox policy.
Installation and Enablement¶
First switch to the DSH Web configuration directory:
cd $env:USERPROFILE\.dsh\profiles\web
Run the installation command:
npm install dsh-copy-tool
After installation, add dsh-copy-tool to the dsh.profile.bundles array in package.json, then restart DSH Web.
Usage Instructions¶
All parameters are required. The expanded lines and target_lines must select the same number of lines; each line in the source file is mapped to the line at the corresponding position in target_lines. Line numbers are 1-based.
Existing target files are edited in place, and unselected content is preserved. A missing target must use consecutive target_lines starting from 1, and will be created as a new file. It is recommended to first use dry_run to check the diff.
Example Configuration¶
Scenario 1: Preview the diff only
{
"source_file": "source.py",
"target_file": "module.py",
"lines": [[633, 644]],
"target_lines": [[1, 12]],
"indent": 0,
"dry_run": true
}
Scenario 2: Write the changes
{
"source_file": "source.py",
"target_file": "module.py",
"lines": [633, [640, 645], 700],
"target_lines": [1, [2, 7], 8],
"indent": 1,
"dry_run": false
}
Notes¶
The plugin runs with the permissions of the current DSH process, so the source code and license should be reviewed before installation. This tool is suitable for scenarios that require precise control over code block migration and refactoring.
Through its fine-grained line operation capabilities, this tool helps perform code refactoring more safely and efficiently within DeepSeek Harness. For more details, see the GitHub repository or the plugin directory.