@zhuifengqug/dsh-mantis 0.0.0-stage → 1.0.10

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.
Files changed (150) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +7 -0
  3. package/README.md +147 -2
  4. package/bin/mantis.js +171 -0
  5. package/client.js +9578 -0
  6. package/cordis.patch.yml +77 -0
  7. package/docs/agents/domain.md +53 -0
  8. package/docs/agents/issue-tracker.md +50 -0
  9. package/docs/agents/triage-labels.md +15 -0
  10. package/docs/banner.svg +18 -0
  11. package/docs/drill-auth-legal.html +58 -0
  12. package/docs/host-0.2.2-migration-2026-11-06.md +82 -0
  13. package/docs/notice/image.png +0 -0
  14. package/docs/notice/laozhang-live-1.jpg +0 -0
  15. package/docs/notice/laozhang-live-2.jpg +0 -0
  16. package/docs/notice/laozhang-wechat-1.jpg +0 -0
  17. package/docs/patches-audit-2026-11-05.md +118 -0
  18. package/docs/preview/dock-auth.png +0 -0
  19. package/docs/preview/dock-clean.png +0 -0
  20. package/docs/preview/dock-drill.png +0 -0
  21. package/docs/preview/own-servers-en.png +0 -0
  22. package/docs/preview/own-servers.png +0 -0
  23. package/docs/preview/rules.png +0 -0
  24. package/docs/preview/settings.png +0 -0
  25. package/docs/redteam-upstream-DISCLOSURE +86 -0
  26. package/docs/redteam-upstream-LICENSE +27 -0
  27. package/docs/system-prompt-patches-2026-11-05.md +421 -0
  28. package/docs/v1.1.34-prompt-inject.md +448 -0
  29. package/icon.svg +38 -0
  30. package/lib/anchor.js +132 -0
  31. package/lib/anchors.js +84 -0
  32. package/lib/apply-progress.js +66 -0
  33. package/lib/asset-table.js +169 -0
  34. package/lib/atomic-files.js +92 -0
  35. package/lib/audit.js +144 -0
  36. package/lib/bin-preflight.js +85 -0
  37. package/lib/boost.js +60 -0
  38. package/lib/capability-protocol.js +32 -0
  39. package/lib/child-process-hide.mjs +87 -0
  40. package/lib/command-registration.js +20 -0
  41. package/lib/continue-retry.js +364 -0
  42. package/lib/core.js +8744 -0
  43. package/lib/default-prompt-inject.en.md +284 -0
  44. package/lib/default-prompt-inject.zh.md +278 -0
  45. package/lib/desktop-entry.js +81 -0
  46. package/lib/desktop-identity.js +100 -0
  47. package/lib/desktop-read-scope.js +33 -0
  48. package/lib/desktop.js +2007 -0
  49. package/lib/drill-grant.js +50 -0
  50. package/lib/extract-asar.js +479 -0
  51. package/lib/hide-console.js +323 -0
  52. package/lib/hooks-deny.js +224 -0
  53. package/lib/host-clean.js +26 -0
  54. package/lib/host-compat.js +114 -0
  55. package/lib/host-layout.js +83 -0
  56. package/lib/host.js +28 -0
  57. package/lib/identity.js +1078 -0
  58. package/lib/index.js +3122 -0
  59. package/lib/instance.js +356 -0
  60. package/lib/maintenance-lock.js +165 -0
  61. package/lib/net-scope.js +241 -0
  62. package/lib/official-update.js +57 -0
  63. package/lib/official-update.wscript +93 -0
  64. package/lib/path-boundary.js +57 -0
  65. package/lib/permission-state.js +72 -0
  66. package/lib/phase1-keep.js +21 -0
  67. package/lib/preset-default.js +205 -0
  68. package/lib/preset-diagnostic.js +47 -0
  69. package/lib/probe.js +70 -0
  70. package/lib/profile-insert.js +406 -0
  71. package/lib/reapply-cli.js +5 -0
  72. package/lib/reapply.js +388 -0
  73. package/lib/redteam/atomic-write.js +28 -0
  74. package/lib/redteam/client.js +4396 -0
  75. package/lib/redteam/evidence-ledger.mjs +507 -0
  76. package/lib/redteam/index.js +657 -0
  77. package/lib/redteam/ip-utils.js +140 -0
  78. package/lib/redteam/platform-config.js +612 -0
  79. package/lib/redteam/preset-composition.js +403 -0
  80. package/lib/redteam/report-replay.js +213 -0
  81. package/lib/redteam/role-section.js +178 -0
  82. package/lib/redteam/schema.js +630 -0
  83. package/lib/redteam/score-rules.js +940 -0
  84. package/lib/redteam/settings.js +78 -0
  85. package/lib/redteam/skill-availability.js +354 -0
  86. package/lib/redteam/skill-fixes.js +529 -0
  87. package/lib/redteam/store-core.js +5430 -0
  88. package/lib/redteam/store.js +80 -0
  89. package/lib/redteam/tools.js +2256 -0
  90. package/lib/redteam/ui.js +1180 -0
  91. package/lib/redteam/validate.js +88 -0
  92. package/lib/refusal-retry.js +122 -0
  93. package/lib/remove-tree.js +66 -0
  94. package/lib/restart-desktop.js +485 -0
  95. package/lib/restart-web.js +144 -0
  96. package/lib/restore-backup.js +21 -0
  97. package/lib/rewind.js +644 -0
  98. package/lib/rules.js +560 -0
  99. package/lib/selfcheck.js +301 -0
  100. package/lib/settle-policy.js +61 -0
  101. package/lib/skills.js +747 -0
  102. package/lib/stream-observation.js +24 -0
  103. package/lib/subagent-control.js +67 -0
  104. package/lib/surface.js +139 -0
  105. package/lib/table-key.js +29 -0
  106. package/lib/table-read.js +18 -0
  107. package/lib/tuning.js +66 -0
  108. package/lib/uninstall-restart.js +80 -0
  109. package/lib/uninstall.js +315 -0
  110. package/lib/update.js +1183 -0
  111. package/lib/web-preflight-entry.js +167 -0
  112. package/lib/web-reclaim.js +151 -0
  113. package/lib/web.js +117 -0
  114. package/lib/zip-extract.js +186 -0
  115. package/locale/en.json +6 -0
  116. package/locale/zh.json +6 -0
  117. package/package.json +106 -4
  118. package/presets/redteam/agent.cordis.yml +390 -0
  119. package/presets/redteam/anchor-gate.mjs +218 -0
  120. package/presets/redteam/preset.yml +3 -0
  121. package/screenshots.json +9 -0
  122. package/scripts/build-client.mjs +74 -0
  123. package/scripts/embed-default-prompt.mjs +33 -0
  124. package/scripts/ensure-profile-bundle.mjs +89 -0
  125. package/scripts/export-engagement-report.mjs +50 -0
  126. package/scripts/patch-client-dock.mjs +454 -0
  127. package/scripts/redteam-setup.sh +487 -0
  128. package/skills/redteam/active-scan.md +34 -0
  129. package/skills/redteam/asset-correlation.md +16 -0
  130. package/skills/redteam/browser-automation.md +82 -0
  131. package/skills/redteam/chisel-tunnel.md +115 -0
  132. package/skills/redteam/cn-proxy-pool.md +90 -0
  133. package/skills/redteam/credential-attack.md +155 -0
  134. package/skills/redteam/dir-bruteforce.md +115 -0
  135. package/skills/redteam/fofa-recon.md +179 -0
  136. package/skills/redteam/frp-tunnel.md +147 -0
  137. package/skills/redteam/fscan-intranet.md +216 -0
  138. package/skills/redteam/gogo-intranet.md +236 -0
  139. package/skills/redteam/kimi-webbridge.md +86 -0
  140. package/skills/redteam/lateral-movement.md +148 -0
  141. package/skills/redteam/nuclei-scan.md +103 -0
  142. package/skills/redteam/passive-recon.md +21 -0
  143. package/skills/redteam/recon-pipeline.md +111 -0
  144. package/skills/redteam/redteam-setup.md +99 -0
  145. package/skills/redteam/shell-handler.md +146 -0
  146. package/skills/redteam/suo5-tunnel.md +63 -0
  147. package/skills/redteam/unauth-exploit.md +151 -0
  148. package/skills/redteam/vps-reverse-shell.md +187 -0
  149. package/skills/redteam/web-fingerprint.md +17 -0
  150. package/skills/redteam/webshell-toolkit.md +88 -0
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, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, or
149
+ MERCHANTABILITY. 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 YuJunZhiXue
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/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ dsh-purge
2
+ Copyright 2026 YuJunZhiXue
3
+
4
+ Source: https://github.com/YuJunZhiXue/dsh-purge
5
+
6
+ This product is licensed under the Apache License, Version 2.0.
7
+ Derivative works must retain this NOTICE and attribution.
package/README.md CHANGED
@@ -1,3 +1,148 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="docs/banner.svg" alt="mantis" width="720">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <h1 align="center">虫珀 · 拒斧(mantis)</h1>
6
+
7
+ <p align="center"><strong>1.0.10</strong> · 适配 DeepSeek Harness <strong>0.2.2-rc.1</strong>(桌面版 / 官方 <code>dsh web</code>)</p>
8
+
9
+ 拒斧装在你自己的机器上,把 DeepSeek Harness 的提示词、审批、沙箱策略摊开,按需清洗、逐条回滚。只改本机 `@deepseek-ai` 包与本地配置,不碰远端。
10
+
11
+ ## 功能
12
+
13
+ ### 拒斧面板
14
+
15
+ 会话标题旁的「拒斧」按钮打开右侧 dock,两页:
16
+
17
+ | 页面 | 做什么 |
18
+ |---|---|
19
+ | **清洗** | 分组显示补丁状态,应用 / 还原 / 卸载,编辑提示词,管理多套规则集 |
20
+ | **演练台** | 授权后使用本机资产与环境;本构建只允许本机实验网段,且不随包附带技能库与知识库 |
21
+
22
+ 首次打开演练台要先读须知、等倒计时、读完并勾选三项;清洗不需要这一步。
23
+
24
+ ![清洗页](docs/preview/dock-clean.png)
25
+
26
+ ### 宿主清洗
27
+
28
+ - **默认文案与策略**:提示词、审批口径、沙箱边界、工具上限一并清洗,官方能力保留,不另造第二身份。
29
+ - **启动自检**:每次启动检查并复打;npm 覆盖 `node_modules` 之后不用手改文件。
30
+ - **逐条可控**:状态分「已应用 / 待清洗 / 漂移 / 不适用」,漂移项原样保留,不会被盲目改写。
31
+ - **只打本机**:目标只有本机已装的官方 `@deepseek-ai/*` 包与 `$DSH_HOME` 下的本地文件。
32
+
33
+ ### 提示词与规则
34
+
35
+ 每一轮的注入来源按顺序决定:
36
+
37
+ 1. 规则库里启用的那一套(写入 `$DSH_HOME/prompt-inject.md`);
38
+ 2. 当前目录勾选的 `AGENTS.md` / `CLAUDE.md`;
39
+ 3. 插件内置的默认提示词。
40
+
41
+ 工作区基线还有 strict / fallback / always 三种取舍,控制是否丢掉宿主自带的 workspace 段落。
42
+
43
+ ### 撤销
44
+
45
+ - 输入框的「撤销一次」「撤销上一轮」只作用于当前会话,不拉分支;被撤回的那一段重新回到输入框,改完再发。
46
+ - 命令面板里 `/mantis-rewind` 等价。
47
+
48
+ ### 回滚与卸载
49
+
50
+ - 每个被改写的文件在第一次应用前都会留 `<文件>.mantis.bak`。
51
+ - **还原**把备份逐字节写回并删除备份;**卸载**先还原,再删注入文件、规则库与插件本体。
52
+ - 应用是幂等的,重复点不会叠加改动。
53
+
54
+ ### 命令
55
+
56
+ ```sh
57
+ mantis --status # 逐条补丁状态
58
+ mantis --apply # 应用
59
+ mantis --revert # 还原
60
+ mantis --uninstall # 卸载
61
+ mantis --edit # 打开提示词
62
+
63
+ /mantis status | apply | revert | uninstall | edit | help
64
+ /mantis-rules list | use <id> | create <id> | delete <id> | reset
65
+ /mantis-rewind
66
+ ```
67
+
68
+ ### 边界
69
+
70
+ - 只面向本机:攻击类任务只允许 loopback 与 RFC1918,域名先解析再判 IP,`.lab` 这类后缀不算白名单。
71
+ - 本构建不含技能库与知识库;不提供公网扫描、第三方站点攻击载荷或游戏作弊相关能力。
72
+
73
+ ## 安装
74
+
75
+ 前置:Node.js ≥ 18;`dsh` 在 PATH 上;宿主是 **0.2.2-rc.1**。本版不再承诺 0.2.1 及更早版本。
76
+
77
+ 安装和「应用」是两件事:装完只是让宿主认识这个插件,**应用**才真正改写宿主文件。
78
+
79
+ ### 1. 装进 profile
80
+
81
+ 在仓库目录执行(`desktop` 换成 `web` 就是官方 `dsh web`):
82
+
83
+ ```powershell
84
+ dsh plugin --profile desktop add .
85
+ ```
86
+
87
+ 或者先打包再装:
88
+
89
+ ```powershell
90
+ npm pack
91
+ dsh plugin --profile desktop add .\zhuifengqug-dsh-mantis-1.0.10.tgz
92
+ ```
93
+
94
+ 这一步会做两件事:把包写进该 profile 的 `dependencies`,并把 `@zhuifengqug/dsh-mantis` 追加到 `dsh.profile.bundles`。**只加依赖、不加 bundles,宿主不会加载插件面板。**
95
+
96
+ 手工等价(`$DSH_HOME/profiles/desktop/package.json`,改前先备份):
97
+
98
+ ```json
99
+ {
100
+ "dependencies": {
101
+ "@zhuifengqug/dsh-mantis": "link:D:/path/to/dsh-mantis"
102
+ },
103
+ "dsh": {
104
+ "profile": {
105
+ "bundles": [
106
+ "...保留原有项...",
107
+ "@zhuifengqug/dsh-mantis"
108
+ ]
109
+ }
110
+ }
111
+ }
112
+ ```
113
+
114
+ 改完在该 profile 目录跑一次 `pnpm install`,确认 `node_modules/@zhuifengqug/dsh-mantis/package.json` 存在。
115
+
116
+ ### 2. 完全退出并重开宿主
117
+
118
+ 桌面版连托盘一起退,再打开 exe;`dsh web` 停掉进程重新起。只重开窗口不算。
119
+
120
+ ### 3. 应用
121
+
122
+ 打开宿主 → 会话标题旁点「拒斧」→ **清洗** → **应用**。成功后宿主会重启一次;没跑完不会重启。
123
+
124
+ 也可以直接用命令行:
125
+
126
+ ```powershell
127
+ node bin\mantis.js --apply
128
+ ```
129
+
130
+ ### 4. 验证
131
+
132
+ ```powershell
133
+ node bin\mantis.js --status
134
+ ```
135
+
136
+ 或聊天里发 `/mantis status`。输出会打印 `DSH_HOME`、宿主版本和逐条状态;`liangshen` 这类没装的第三方预设显示为 skipped,不阻塞应用。
137
+
138
+ 本机若装了多个 dsh(例如 npx 缓存里的旧包),`--status` 可能选错安装。用环境变量钉死目标:
139
+
140
+ ```powershell
141
+ $env:DSH_BASE = "D:\Deepseek Harness\resources\app.asar\dsh\node_modules\@deepseek-ai"
142
+ ```
143
+
144
+ 桌面版是密封的 `app.asar` 时,状态里的部分条目会显示为缺失——归档内文件无法就地改写,需要先按官方流程解包到 `resources/app` 再应用。
145
+
146
+ ### 卸载
147
+
148
+ 面板 → 清洗 → **卸载**;或 `node bin\mantis.js --uninstall`。会先还原补丁再删插件本体,并把仍指向 `redteam` 预设的默认项改回 `standard`。
package/bin/mantis.js ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+
3
+ import * as core from "../lib/core.js";
4
+ import * as rules from "../lib/rules.js";
5
+ import * as reapply from "../lib/reapply.js";
6
+
7
+ const args = process.argv.slice(2);
8
+
9
+ function printStatus(state) {
10
+ const out = [];
11
+ out.push("mantis 状态 / Status");
12
+ out.push(" 宿主 / surface " + (state.surface || "web"));
13
+ out.push(" DSH_HOME " + state.dsh_home);
14
+ if (state.desktop_install) out.push(" 桌面安装 " + state.desktop_install);
15
+ if (state.ai_base) {
16
+ out.push(" 插件根 / root " + state.ai_base);
17
+ for (const [key, fp] of Object.entries(state.files)) {
18
+ out.push(` ${key.padEnd(22)} ${fp}`);
19
+ }
20
+ } else {
21
+ out.push(" 插件根 / root " + core.missingAiBaseMessage());
22
+ }
23
+ out.push(` shim 目录 ${state.shim_dir || "未定位 / not found"}`);
24
+ out.push(` 备份 / backup ${state.has_backup ? "有 / yes" : "无 / no"}`);
25
+ out.push(` 注入文件 ${state.override_path}`);
26
+ out.push(` 注入状态 ${state.override_status}`);
27
+ out.push("");
28
+ out.push(` 补丁 ${state.patches_applied}/${core.ALL_PATCHES.length} 已清洗, ${state.patches_pending} 待清洗`
29
+ + (state.patches_drifted ? `, ${state.patches_drifted} 漂移(官方原文已改,需更新 pattern)` : ""));
30
+ if (state.host_version) {
31
+ const compat = state.host_supported === false ? ` ← 未适配:插件声明 ${state.host_target || "?"}` : "";
32
+ out.push(` 宿主版本 / host ${state.host_version}${compat}`);
33
+ }
34
+ for (const p of core.ALL_PATCHES) {
35
+ const s = state.patch_status[p.id];
36
+ const mark = s === "applied" ? "✓" : s === "pending" ? "✗" : s === "drifted" ? "!" : "·";
37
+ out.push(` ${mark} [#${String(p.id).padEnd(2)}] ${p.name.padEnd(30)} ${p.layer}/${p.layer_en} — ${s}`);
38
+ }
39
+ out.push("");
40
+ out.push(` shim: dsh.cmd=${state.shim_cmd} dsh.ps1=${state.shim_ps1} dsh=${state.shim_bin}`);
41
+ return out.join("\n");
42
+ }
43
+
44
+ async function main() {
45
+ const mode = args.find((a) => ["--apply", "--revert", "--uninstall", "--status", "--edit", "--help"].includes(a));
46
+
47
+ if (mode === "--help" || args.includes("-h")) {
48
+ console.log(`mantis 用法:
49
+ mantis --status 显示状态
50
+ mantis --apply 应用全部清洗(提示词+代码+shim+override)
51
+ mantis --revert 回滚还原
52
+ mantis --uninstall 卸载插件(已应用则先还原)
53
+ mantis --edit 编辑注入文件 prompt-inject.md
54
+ mantis --help 帮助`);
55
+ return;
56
+ }
57
+
58
+ const state = await core.gatherState();
59
+ console.log(printStatus(state));
60
+ console.log("");
61
+
62
+ if (mode === "--apply") {
63
+ if (!state.ai_base) {
64
+ console.log("[ERROR] " + core.missingAiBaseMessage());
65
+ console.log(" fix: 把 DSH_BASE 指到含 dsh-agent-instructions/lib 的 @deepseek-ai 目录");
66
+ process.exit(1);
67
+ }
68
+ const inject = rules.resolveInjectText(state.dsh_home);
69
+ if (!inject.text) {
70
+ console.log("[ERROR] 提示词和规则集都是空的,必须先添加提示词");
71
+ process.exit(1);
72
+ }
73
+ const { hosts, report } = await core.applyPatchesAllHosts(core.ALL_PATCHES, {
74
+ preserveClientBundles: false,
75
+ forApply: true,
76
+ });
77
+ for (const h of hosts) console.log(` 宿主 / host → ${h.aiBase}`);
78
+ for (const r of report) {
79
+ const m = r.status === "applied" ? "✓ 已清洗" : r.status === "already" ? "- 已是最新" : r.status === "missing_file" ? "⚠ 文件缺失" : `✗ ${r.status}`;
80
+ console.log(` ${m} patch #${String(r.patch_id).padEnd(2)} ${r.name}`);
81
+ }
82
+ const flashHost = hosts[0]?.aiBase || state.ai_base;
83
+ const flash = core.silenceCmdFlash(flashHost);
84
+ console.log(` cmd-flash=${flash.entry} phase-1=${flash.phase1} ok=${flash.ok}`);
85
+ if (hosts.length > 1) {
86
+ console.log(` 多宿主 / multi-host: ${hosts.length} 份 @deepseek-ai 已清洗`);
87
+ }
88
+ console.log(inject.source === "rule"
89
+ ? " - 使用当前规则集,不改写提示词文件"
90
+ : " - 使用已有提示词文件");
91
+ if (state.shim_dir) {
92
+ const r = await core.patchShim(state.shim_dir);
93
+ for (const [fname, st] of Object.entries(r)) {
94
+ if (st === "patched") console.log(` ✓ shim ${fname} 注入 / injected`);
95
+ else if (st === "already_patched") console.log(` - shim ${fname} 已注入 / already injected`);
96
+ else if (st === "missing") console.log(` - shim ${fname} 不存在 / missing`);
97
+ else console.log(` ⚠ shim ${fname}: ${st}`);
98
+ }
99
+ } else {
100
+ console.log(" ⚠ 未定位 shim 目录,跳过注入");
101
+ }
102
+ const failed = core.summarizeApplyReport(report).failed || [];
103
+ console.log("");
104
+ if (failed.length > 0) {
105
+ console.log(`✗ 完成但有 ${failed.length} 个补丁失败 / finished with ${failed.length} failed patch(es)`);
106
+ process.exit(1);
107
+ }
108
+ // 面板点应用会打戳;CLI 也要打,否则下次启动 settle 以为没对齐又重打一遍(#202)。
109
+ try {
110
+ reapply.markPatchesApplied();
111
+ } catch (e) {
112
+ console.log(` ⚠ 写入应用记录失败 / failed to write applied stamp: ${e && e.message ? e.message : e}`);
113
+ }
114
+ console.log("全部完成 / All done。重启 dsh 生效 / Restart dsh to take effect.");
115
+ } else if (mode === "--revert") {
116
+ if (state.ai_base || core.enumeratePatchAiBases().length) {
117
+ const { reverted, errors } = await core.revertAllHosts();
118
+ for (const p of reverted) console.log(` ✓ 已还原 / Reverted ${p}`);
119
+ for (const [p, e] of errors) console.log(` ⚠ 还原失败 ${p}: ${e}`);
120
+ if (reverted.length === 0) console.log(" - 没有补丁备份可还原 / no patch backup");
121
+ }
122
+ if (state.shim_dir) {
123
+ const r = await core.revertShim(state.shim_dir);
124
+ for (const [fname, st] of Object.entries(r)) {
125
+ if (st === "reverted" || st === "stripped_inject") console.log(` ✓ shim ${fname}: ${st}`);
126
+ else console.log(` - shim ${fname}: ${st}`);
127
+ }
128
+ }
129
+ console.log("");
130
+ console.log("回滚完成 / Revert done。重启 dsh 后恢复 / restart to restore.");
131
+ console.log("注: prompt-inject.md 保留(用户文件)/ prompt-inject.md kept (user file)");
132
+ } else if (mode === "--uninstall") {
133
+ const { uninstallPurge } = await import("../lib/uninstall.js");
134
+ const result = await uninstallPurge();
135
+ if (result.applied) console.log(" 已检测到补丁,已还原回原版。");
136
+ else console.log(" 未检测到已应用补丁,仍会清除插件文件。");
137
+ if (result.override?.removed) console.log(` 已删除 ${result.override.path}`);
138
+ if (result.stripped?.length) console.log(` 已从 profile 移除: ${result.stripped.join(", ")}`);
139
+ for (const e of result.errors || []) console.log(` ⚠ ${e}`);
140
+ if (!result.ok) {
141
+ console.log(" 卸载中止:还原失败,插件文件未删除。");
142
+ process.exit(1);
143
+ }
144
+ /* 命令行卸载没有「重启后助手」这一步:插件目录不会自己消失,得在这里删。
145
+ (界面卸载是把这一步交给独立助手,等端口释放后再删。) */
146
+ const fs = await import("node:fs");
147
+ for (const dir of result.cleanup || []) {
148
+ try { fs.rmSync(dir, { recursive: true, force: true, maxRetries: 8, retryDelay: 120 }); }
149
+ catch (e) { console.log(` ⚠ 未能删除 ${dir}: ${e && e.message ? e.message : e}`); }
150
+ }
151
+ console.log("");
152
+ console.log("卸载完成。请重启 dsh。");
153
+ } else if (mode === "--edit") {
154
+ const r = core.editOverride(state.dsh_home);
155
+ if (!r.ok && r.needCreate) {
156
+ await core.installOverride(state.dsh_home, true);
157
+ console.log(` ✓ 已创建默认注入文件:${state.override_path}`);
158
+ core.editOverride(state.dsh_home);
159
+ } else {
160
+ console.log(` → 已打开 ${r.editor} 编辑注入文件:${r.path}`);
161
+ }
162
+ console.log(" 编辑完成后重启 dsh 生效。");
163
+ } else {
164
+ console.log("默认不清洗,使用 --apply 应用清洗。");
165
+ }
166
+ }
167
+
168
+ main().catch((e) => {
169
+ console.error("[mantis] error:", e);
170
+ process.exit(1);
171
+ });