@michengai/dsh-simplify 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ [简体中文](CHANGELOG.zh-CN.md)
4
+
5
+ ## 0.1.0 - 2026-09-06
6
+
7
+ - Add `/simplify` for current changes, staged changes, a specified commit, and explicit files or directories.
8
+ - Add a Chinese editing-task prompt with scope, behavior, snapshot, and verification requirements.
9
+ - Expand simplification guidance, behavior-equivalence checks, project instruction discovery, concurrent-edit handling, and validation reporting to avoid over-abstraction, out-of-scope edits, and unsupported optimizations.
10
+ - Use DSH subprocess argument arrays and NUL-delimited parsing for Chinese characters, spaces in paths, and untracked files.
11
+ - Prevent queuing on Git failures, cancellation, timeouts, and truncation; bound file counts, content size, and prompt size.
12
+ - Add staged consistency checks, HEAD/index/content verification, and previous-commit fallback in default mode only.
13
+ - Add real Git regression tests and an optional integration test using real DSH services.
14
+ - Parse patch bodies with old/new line-count validation, excluding context lines and rejecting incomplete hunks.
15
+ - Initialize the public repository and bilingual documentation under Apache-2.0.
16
+
17
+ ### Known Issues
18
+
19
+ - Some host interfaces do not visibly display the `没有可简化的当前代码行` (no eligible current lines) command result. The backend returns the result without making a model request; feedback visibility remains under investigation.
@@ -0,0 +1,19 @@
1
+ # 变更记录
2
+
3
+ [English](CHANGELOG.md)
4
+
5
+ ## 0.1.0 - 2026-09-06
6
+
7
+ - 新增 `/simplify`:当前改动、暂存区、指定提交和显式文件或目录范围。
8
+ - 新增中文编辑任务提示词,明确范围、行为、快照与验证要求。
9
+ - 完善简化检查方向、行为等价判断、项目规范读取、并发编辑保护及验证报告,避免过度抽象、越界修改和无依据的优化。
10
+ - 使用 DSH subprocess 参数数组及 NUL 分隔解析,支持中文、空格路径和未跟踪文件。
11
+ - Git 错误、取消、超时及截断时阻止入队;提供文件数、内容大小和提示词上限。
12
+ - 增加暂存区一致性保护、HEAD/index/内容复核及仅默认模式的上一提交回看。
13
+ - 新增真实 Git 回归测试和可选真实 DSH 服务集成测试。
14
+ - 按补丁正文核对新旧行数,排除上下文行并拒绝残缺块。
15
+ - 初始化公开仓库及双语文档,项目采用 Apache-2.0。
16
+
17
+ ### 已知问题
18
+
19
+ - 部分宿主界面未明显显示“没有可简化的当前代码行”的命令结果。后端已返回结果且不会发起模型请求,反馈可见性仍待排查。
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 MichengAI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ <p align="center">
2
+ <img src="assets/branding/dsh-simplify-banner.png" alt="DSH Simplify" width="100%">
3
+ </p>
4
+
5
+ <div align="center">
6
+
7
+ # DSH Simplify
8
+
9
+ **Simplify recently changed code in DeepSeek Harness while preserving behavior.**
10
+
11
+ [简体中文](README.zh-CN.md) · [Installation](#installation) · [Usage](#usage) · [Troubleshooting](#troubleshooting) · [Changelog](CHANGELOG.md) · [Apache-2.0](LICENSE)
12
+
13
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
14
+ [![DSH Web Plugin](https://img.shields.io/badge/DSH%20Web-Plugin-0f766e.svg)](https://github.com/deepseek-ai/deepseek-harness)
15
+ [![Node.js 22.19+](https://img.shields.io/badge/Node.js-22.19%2B-339933.svg?logo=node.js&logoColor=white)](https://nodejs.org/)
16
+
17
+ </div>
18
+
19
+ DSH Simplify collects changed files, line ranges, and content snapshots from Git when you run `/simplify`. The current Agent then improves clarity within that scope while preserving functionality.
20
+
21
+ This is a community-maintained plugin, not an official DeepSeek AI product. It supports DSH Web and desktop apps that include DSH Web.
22
+
23
+ The plugin has its own review prompt, patch-body parser, Git collection, and DSH integration. Command messages and prompts are in Simplified Chinese.
24
+
25
+ ## Features
26
+
27
+ - **Scoped review**: current changes, staged changes, a specified commit, or selected files and directories.
28
+ - **New files**: review untracked files in full, including repositories without an initial commit.
29
+ - **Cross-platform paths**: Git argument arrays and NUL-delimited parsing support Chinese characters, spaces, and quotes in file names.
30
+ - **Bounded execution**: Git errors, cancellation, timeouts, truncated output, and conflicts prevent incomplete reviews from being queued.
31
+ - **Staged consistency**: reject selected staged files that also have unstaged changes to avoid mismatched line numbers.
32
+ - **Snapshot checks**: verify HEAD, the index, and content hashes before queuing; ask the Agent to check again before editing.
33
+ - **Previous-commit review**: only the default mode may fall back to HEAD compared with its first parent.
34
+
35
+ ## Installation
36
+
37
+ Requires Node.js >= 22.19, Git on PATH, and DSH `0.1.2-rc.1` with the `commands` and `subprocess` services. The session must have a local Git working directory. Tested on Windows; Linux and macOS have not been verified on those systems.
38
+
39
+ The current version is `0.1.0`, available through npm, a packaged archive, or source installation. The examples use the `web` profile; replace it for your environment. Disable other plugins that register `/simplify` before installation.
40
+
41
+ ### From npm
42
+
43
+ ```powershell
44
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
45
+ $OutputEncoding = [System.Text.Encoding]::UTF8
46
+
47
+ dsh plugin --profile web add @michengai/dsh-simplify@0.1.0 --registry=https://registry.npmjs.org/
48
+ ```
49
+
50
+ ### From Source
51
+
52
+ ```powershell
53
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
54
+ $OutputEncoding = [System.Text.Encoding]::UTF8
55
+
56
+ git clone https://github.com/MichengAI/dsh-simplify.git
57
+ Set-Location dsh-simplify
58
+ npm ci --ignore-scripts
59
+ npm run check
60
+ dsh plugin --profile web add . --ignore-scripts
61
+ ```
62
+
63
+ The entry point is `lib/index.js`, so build before installing. Keep the source directory when the profile uses a local link.
64
+
65
+ ### From a Local Package
66
+
67
+ Download the tgz from the [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.0), or run `npm pack` in the source directory, then run this from the package directory:
68
+
69
+ ```powershell
70
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
71
+ $OutputEncoding = [System.Text.Encoding]::UTF8
72
+
73
+ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
74
+ ```
75
+
76
+ ### Reload and Verify
77
+
78
+ Install or update after the current task finishes, since desktop apps may reload automatically. If the plugin does not take effect, use the desktop app's reload action or restart `dsh web`; refreshing the browser alone is insufficient.
79
+
80
+ Run `dsh --profile web --dump-config` and confirm that it includes `michengai-simplify`. Check for sensitive settings before sharing the full configuration. Then enter `/simplify` in a session associated with a Git project.
81
+
82
+ ## Usage
83
+
84
+ | Input | Scope |
85
+ | --- | --- |
86
+ | `/simplify` | Net changes from HEAD to the working tree, including untracked files; fall back to the last commit only when there are no changes |
87
+ | `/simplify --staged` | Staged changes only; reject selected staged files that also have unstaged changes |
88
+ | `/simplify --ref=main` | The specified commit to the working tree, including untracked files; no fallback |
89
+ | `/simplify --ref HEAD` | Explicit HEAD scope without previous-commit fallback |
90
+ | `/simplify src/a.ts "src/中文 文件.ts"` | Changes in selected files; review untracked files in full |
91
+ | `/simplify src` | Expand changed files within a directory |
92
+ | `/simplify -- --special.ts` | Use the option terminator for paths starting with a hyphen |
93
+
94
+ - Paths are relative to the session directory. Absolute paths inside the repository are supported; prompts use paths relative to the repository root.
95
+ - Single and double quotes group paths containing spaces; backslashes remain path characters. No shell expansion, wildcard expansion, or command substitution is performed.
96
+ - `--ref` accepts branches, tags, and single-commit expressions, not `a..b` or `a...b`. It cannot be combined with `--staged`.
97
+ - New files can be reviewed before the initial commit. A clean repository with only one commit returns no changes.
98
+ - Previous-commit fallback compares HEAD with its first parent. Merge commits do not receive a multi-parent review.
99
+
100
+ ## Command Results
101
+
102
+ | Result | Meaning |
103
+ | --- | --- |
104
+ | `已提交 N 个文件的简化审查` | Review of N files was queued. The Agent has not necessarily finished editing or testing. |
105
+ | `没有可简化的当前代码行` | No current lines are eligible. No model request is made; skipped-file details may be included. |
106
+ | An error message | A reliable scope could not be established. No model request is made; address the reported issue before retrying. |
107
+
108
+ ## Troubleshooting
109
+
110
+ **The input clears after Enter, but no answer appears.** Empty reviews do not start the Agent. In a reported case, the backend returned success and skipped two CHANGELOG files because no eligible current lines were found. Some host interfaces do not visibly display these command results; feedback visibility is still under investigation. A successful backend response does not establish that the UI displayed it.
111
+
112
+ **The current directory is not a Git repository.** Use a session in the correct Git project, or initialize the project yourself. The plugin does not initialize repositories, stage files, or create commits.
113
+
114
+ **Staged files also have unstaged changes.** Save or resolve those changes yourself before using `--staged`, or use default `/simplify` to review net working-tree changes. The plugin does not reset or stash changes.
115
+
116
+ **The installer reports missing peer dependencies.** Official packages may be supplied by the DSH host runtime. Verify actual resolved versions and backend loading before installing duplicate host packages into the profile. Versions must still satisfy `package.json`.
117
+
118
+ **Timeout, excessive output, or an outdated snapshot.** Narrow the scope to specific files or directories and retry after concurrent edits finish.
119
+
120
+ ## Execution Boundaries
121
+
122
+ The plugin performs read-only Git queries and local file reads. It does not automatically run `git add`, commit, reset, or stash. Git arguments are passed through DSH `subprocess` as `argv`, independent of PowerShell or Bash quoting rules.
123
+
124
+ Git failures, signals, cancellation, timeouts, truncated output, unresolved conflicts, and stale snapshots prevent prompt delivery. They are not interpreted as an empty diff. The patch parser counts old and new lines against each hunk header, rejects incomplete bodies, and excludes context lines from editable ranges. Explicit paths that do not exist, are ignored, or lie outside the repository return errors.
125
+
126
+ Deleted files, deletion-only hunks, rename-only changes, binary files, non-regular files, and files over 5 MiB are excluded from editable ranges with reasons. Submodules are excluded from diff collection. Skipping all detected changes does not expand the review scope. Limits are 200 changed files, 30 seconds per Git command, and 60 seconds for scope collection, with up to 1 additional second for process termination. Git stdout is capped at 8 MiB, stderr at 64 KiB, and prompts at 128 KiB.
127
+
128
+ `--staged` first checks that selected staged files match the working tree. Before queuing, the plugin rechecks the index, HEAD, and file SHA-256 hashes to avoid applying index line numbers to different working-tree content. The Agent is instructed to verify snapshots again before editing and stop simplifying a file if its content has changed, requiring a new command invocation.
129
+
130
+ **Scope is a prompt instruction, not a file-write permission boundary.** The Agent edits and tests using host tools and user authorization. This plugin does not intercept writes from other tools or guarantee that files remain unchanged after queuing. A queued review is not a completed simplification.
131
+
132
+ The implementation assumes the local filesystem and local subprocess share the same workspace. Remote subprocess and remote filesystem combinations have not been verified.
133
+
134
+ ## Uninstall
135
+
136
+ ```powershell
137
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
138
+ $OutputEncoding = [System.Text.Encoding]::UTF8
139
+
140
+ dsh plugin --profile web remove @michengai/dsh-simplify
141
+ ```
142
+
143
+ Reload DSH manually if the desktop app does not reload automatically. Uninstalling does not undo code changes already made by the Agent.
144
+
145
+ ## Development and Verification
146
+
147
+ ```powershell
148
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
149
+ $OutputEncoding = [System.Text.Encoding]::UTF8
150
+ npm ci --ignore-scripts
151
+ npm run check
152
+ npm pack --dry-run
153
+ ```
154
+
155
+ Tests use real temporary Git repositories to cover paths, untracked files, fallback, conflicts, staged mismatches, stale snapshots, and execution errors. Fixtures are created under `.test-tmp` and cleaned up on normal completion.
156
+
157
+ `tests/host.test.mjs` looks for a DSH runtime at `%USERPROFILE%\.dsh\profiles\node_modules`. Set `DSH_RUNTIME_ROOT` to use another runtime's node_modules path. When detected, it runs isolated integration checks for real service registration, Git execution, message delivery, and disposal; otherwise, that test is explicitly skipped. Tests do not call a model or modify installed profiles.
158
+
159
+ | Path | Responsibility |
160
+ | --- | --- |
161
+ | `src/args.ts` | Command argument parsing |
162
+ | `src/exec.ts` | DSH subprocess, Git failures, cancellation, and timeouts |
163
+ | `src/git.ts` | Git scope, NUL parsing, line ranges, and snapshot verification |
164
+ | `src/prompt.ts` | Editing task, scope, and verification instructions |
165
+ | `src/command.ts`, `src/index.ts` | Command handling, delivery, and lifecycle |
166
+ | `tests` | Regression and host integration checks |
167
+
168
+ ## License
169
+
170
+ [Apache-2.0](LICENSE), Copyright 2026 MichengAI.
@@ -0,0 +1,170 @@
1
+ <p align="center">
2
+ <img src="assets/branding/dsh-simplify-banner.png" alt="DSH Simplify" width="100%">
3
+ </p>
4
+
5
+ <div align="center">
6
+
7
+ # DSH Simplify
8
+
9
+ **在 DeepSeek Harness 中简化最近改动的代码,保持原有功能。**
10
+
11
+ [English](README.md) · [安装](#安装) · [用法](#用法) · [故障排查](#故障排查) · [更新日志](CHANGELOG.zh-CN.md) · [Apache-2.0](LICENSE)
12
+
13
+ [![许可证:Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-blue.svg)](LICENSE)
14
+ [![DSH Web Plugin](https://img.shields.io/badge/DSH%20Web-Plugin-0f766e.svg)](https://github.com/deepseek-ai/deepseek-harness)
15
+ [![Node.js 22.19+](https://img.shields.io/badge/Node.js-22.19%2B-339933.svg?logo=node.js&logoColor=white)](https://nodejs.org/)
16
+
17
+ </div>
18
+
19
+ DeepSeek Harness 代码简化插件。运行 `/simplify` 后,插件收集 Git 变更文件、行号与内容快照,由当前 Agent 在限定范围内改进代码清晰度,保持功能不变。
20
+
21
+ 本项目为社区插件,并非 DeepSeek AI 官方产品。支持 DSH Web 及集成 DSH Web 的桌面应用。
22
+
23
+ 审查提示词、补丁正文解析、Git 收集与 DSH 适配均由本项目实现。命令文案及提示词使用简体中文。
24
+
25
+ ## 功能概览
26
+
27
+ - **限定审查范围**:当前改动、暂存区、指定提交、指定文件或目录。
28
+ - **包含新增文件**:未跟踪文件按整文件审查,支持尚无首次提交的仓库。
29
+ - **跨平台路径**:Git 参数数组与 NUL 分隔解析,支持中文、空格和引号文件名。
30
+ - **执行失败有边界**:Git 错误、取消、超时、截断和冲突时不提交不完整的审查任务。
31
+ - **防止暂存区行号错位**:所选暂存文件仍有未暂存改动时拒绝执行。
32
+ - **快照复核**:提交提示词前复核 HEAD、index 和内容哈希,要求 Agent 编辑前再次验证。
33
+ - **提交后回看**:仅默认模式允许回看 HEAD 相对第一父提交的差异。
34
+
35
+ ## 安装
36
+
37
+ 要求 Node.js >= 22.19、PATH 中可执行的 Git,以及提供 `commands`、`subprocess` 服务的 DSH `0.1.2-rc.1`。会话需要关联本地 Git 工作目录。Windows 已实测,Linux/macOS 尚未在对应系统验证。
38
+
39
+ 当前版本为 `0.1.0`,支持 npm、安装包和源码安装。以下示例使用 `web` profile,请按实际环境替换。安装前停用其他注册 `/simplify` 的插件。
40
+
41
+ ### 从 npm 安装
42
+
43
+ ```powershell
44
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
45
+ $OutputEncoding = [System.Text.Encoding]::UTF8
46
+
47
+ dsh plugin --profile web add @michengai/dsh-simplify@0.1.0 --registry=https://registry.npmjs.org/
48
+ ```
49
+
50
+ ### 从源码安装
51
+
52
+ ```powershell
53
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
54
+ $OutputEncoding = [System.Text.Encoding]::UTF8
55
+
56
+ git clone https://github.com/MichengAI/dsh-simplify.git
57
+ Set-Location dsh-simplify
58
+ npm ci --ignore-scripts
59
+ npm run check
60
+ dsh plugin --profile web add . --ignore-scripts
61
+ ```
62
+
63
+ 入口为 `lib/index.js`,必须先构建再安装;profile 使用本地链接时需要保留源码目录。
64
+
65
+ ### 从本地安装包安装
66
+
67
+ 从 [GitHub Release](https://github.com/MichengAI/dsh-simplify/releases/tag/v0.1.0) 下载 tgz,或在源码目录运行 `npm pack` 生成安装包,然后在安装包所在目录执行:
68
+
69
+ ```powershell
70
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
71
+ $OutputEncoding = [System.Text.Encoding]::UTF8
72
+
73
+ dsh plugin --profile web add .\michengai-dsh-simplify-0.1.0.tgz --ignore-scripts
74
+ ```
75
+
76
+ ### 重新加载与确认
77
+
78
+ 请在当前任务结束后安装或更新,桌面应用可能自动重载。若未生效,使用桌面应用的重新加载功能,或重启 `dsh web`;仅刷新浏览器不够。
79
+
80
+ 执行 `dsh --profile web --dump-config`,确认包含 `michengai-simplify`。分享完整配置前先检查其中是否包含敏感设置。然后在 Git 项目会话中输入 `/simplify`。
81
+
82
+ ## 用法
83
+
84
+ | 输入 | 范围 |
85
+ | --- | --- |
86
+ | `/simplify` | HEAD 到当前工作区的净改动,包含未跟踪新增文件;确实没有改动时回看最近一次提交 |
87
+ | `/simplify --staged` | 仅暂存区;所选暂存文件另有未暂存改动时拒绝执行 |
88
+ | `/simplify --ref=main` | 指定提交到当前工作区的差异,包含未跟踪文件;不回退其他提交 |
89
+ | `/simplify --ref HEAD` | 显式 HEAD 范围,不启动上一提交回看 |
90
+ | `/simplify src/a.ts "src/中文 文件.ts"` | 仅指定文件的改动;未跟踪文件按整文件处理 |
91
+ | `/simplify src` | 展开目录中的变更文件 |
92
+ | `/simplify -- --special.ts` | 选项终止符后可使用以连字符开头的路径 |
93
+
94
+ - 路径相对当前会话目录,支持仓库内绝对路径;提示词统一使用仓库根目录相对路径。
95
+ - 支持单双引号组合带空格路径,反斜杠按路径字符保留;不执行 Shell 展开、通配符或命令替换。
96
+ - `--ref` 支持分支、标签和单个提交表达式,不支持 `a..b` / `a...b`;不能与 `--staged` 混用。
97
+ - 没有首次提交时仍可审查新增文件;只有一个提交且工作区干净时直接返回无变更。
98
+ - 上一提交回看相对于 HEAD 第一父提交;merge commit 不做多父合并审查。
99
+
100
+ ## 命令结果
101
+
102
+ | 返回结果 | 含义 |
103
+ | --- | --- |
104
+ | `已提交 N 个文件的简化审查` | 审查任务已入队,不代表 Agent 已完成编辑或测试。 |
105
+ | `没有可简化的当前代码行` | 没有可操作的当前行,不发起模型请求;结果可能附带跳过明细。 |
106
+ | 错误信息 | 无法可靠建立审查范围,不发起模型请求;修正所报问题后再试。 |
107
+
108
+ ## 故障排查
109
+
110
+ **回车后输入框清空,但没有回答。** 空审查不会启动 Agent。已收到的用户反馈中,后端返回成功,但两份 CHANGELOG 被判定没有可简化的当前行而跳过;部分宿主界面未明显展示这类命令结果,反馈可见性仍待排查。后端成功不等于界面已经显示结果。
111
+
112
+ **当前目录不是 Git 仓库。** 在正确的 Git 项目会话中执行,或自行初始化项目仓库。插件不会自动初始化仓库、暂存或提交。
113
+
114
+ **暂存文件还有未暂存改动。** 先自行保存或处理这些改动,再运行 `--staged`;也可用默认 `/simplify` 审查当前工作区的净改动。插件不会自动重置或 stash。
115
+
116
+ **安装器提示 peer 依赖缺失。** 官方包可能由 DSH 宿主运行时提供。应核实实际模块解析版本和后端加载结果,不要直接向 profile 重复安装宿主包;版本仍需满足 `package.json`。
117
+
118
+ **超时、输出超限或快照过期。** 使用具体文件或目录缩小范围,并在并发编辑结束后重试。
119
+
120
+ ## 执行边界
121
+
122
+ 插件只执行 Git 只读查询和读取本地文件,不自动 `git add`、提交、重置或存储工作区。Git 参数通过 DSH `subprocess` 的 `argv` 传递,不依赖 PowerShell/Bash 引用规则。
123
+
124
+ Git 失败、信号终止、取消、超时、输出截断、未解决冲突和过期快照都会阻止提示词投递,不将它们当作无改动。补丁解析器按正文核对每块的新旧行数,拒绝残缺正文,并排除上下文行。显式路径不存在、被忽略或位于仓库外时返回错误。
125
+
126
+ 删除文件、纯删除行、仅重命名、二进制文件、非普通文件及大于 5 MiB 的文件不进入可编辑范围,并说明跳过原因。子模块不纳入 diff 收集。已检测到的改动全部被跳过时,不会因此扩大到其他范围。最多收集 200 个变更文件,单次 Git 最多 30 秒,整个范围收集最多 60 秒(进程终止还有最多 1 秒宽限);Git stdout 上限 8 MiB、stderr 64 KiB,提示词上限 128 KiB。
127
+
128
+ `--staged` 先确认所选暂存文件与工作区一致,并在入队前再次核对暂存区、HEAD 和文件 SHA-256,避免把 index 行号直接用于不同的工作区内容。Agent 编辑前还需复核内容快照;内容变化时停止该文件的简化并重新运行命令。
129
+
130
+ **修改范围是提示词约束,不是文件写入权限隔离。** Agent 按宿主工具和用户授权执行修改及测试;本插件没有拦截其他工具的写入,也不能保证排队后文件不再变化。不要把“已提交审查”理解成“已完成简化”。
131
+
132
+ 实现针对本地文件系统与本地 subprocess 同一工作区,未验证远程 subprocess 或远程文件系统组合。
133
+
134
+ ## 卸载
135
+
136
+ ```powershell
137
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
138
+ $OutputEncoding = [System.Text.Encoding]::UTF8
139
+
140
+ dsh plugin --profile web remove @michengai/dsh-simplify
141
+ ```
142
+
143
+ 若桌面应用未自动重载,手动重新加载 DSH。卸载不会撤销 Agent 已产生的代码修改。
144
+
145
+ ## 开发与验证
146
+
147
+ ```powershell
148
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
149
+ $OutputEncoding = [System.Text.Encoding]::UTF8
150
+ npm ci --ignore-scripts
151
+ npm run check
152
+ npm pack --dry-run
153
+ ```
154
+
155
+ 测试使用真实临时 Git 仓库,覆盖路径、未跟踪文件、回退、冲突、暂存区错位、快照过期及执行错误。测试夹具位于 `.test-tmp`,正常结束时自动清理。
156
+
157
+ `tests/host.test.mjs` 检测 `%USERPROFILE%\.dsh\profiles\node_modules` 的 DSH 运行时;也可通过 `DSH_RUNTIME_ROOT` 指定其 node_modules 路径。检测到时执行隔离的真实服务注册、Git 执行、消息投递与卸载测试;缺失时明确标为跳过。测试不调用模型,不修改已安装 profile。
158
+
159
+ | 目录 | 职责 |
160
+ | --- | --- |
161
+ | `src/args.ts` | 命令参数解析 |
162
+ | `src/exec.ts` | DSH subprocess 与 Git 错误、取消、超时处理 |
163
+ | `src/git.ts` | Git 范围选择、NUL 解析、行号与快照复核 |
164
+ | `src/prompt.ts` | 编辑任务、范围与验证提示词 |
165
+ | `src/command.ts`、`src/index.ts` | 命令处理、投递及生命周期 |
166
+ | `tests` | 回归与宿主集成验证 |
167
+
168
+ ## 许可
169
+
170
+ [Apache-2.0](LICENSE),Copyright 2026 MichengAI。
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: michengai-simplify
3
+ name: '@michengai/dsh-simplify'
package/lib/args.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface SimplifyOptions {
2
+ readonly files: readonly string[];
3
+ readonly staged: boolean;
4
+ readonly ref: string;
5
+ readonly explicitRef: boolean;
6
+ }
7
+ /** 解析斜杠命令参数;引号用于组合路径,反斜杠按路径字符保留。非法输入抛出 Error。 */
8
+ export declare function parseArgs(input: string): SimplifyOptions;