@keith9681/dsh-sidebar 0.15.2

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 (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/README_EN.md +0 -0
  4. package/cordis.patch.yml +49 -0
  5. package/lib/client-editor.js +34651 -0
  6. package/lib/client-mermaid.js +200629 -0
  7. package/lib/client-registry.js +13388 -0
  8. package/lib/client-terminal.js +8904 -0
  9. package/lib/client.js +13388 -0
  10. package/lib/index.js +3959 -0
  11. package/lib/invariant.js +22 -0
  12. package/lib/types/agent-pty.d.ts +226 -0
  13. package/lib/types/browser-probe.d.ts +15 -0
  14. package/lib/types/bundle-route.d.ts +12 -0
  15. package/lib/types/client/BrowserView.d.ts +22 -0
  16. package/lib/types/client/DiffTab.d.ts +6 -0
  17. package/lib/types/client/DiffView.d.ts +51 -0
  18. package/lib/types/client/EditorHost.d.ts +12 -0
  19. package/lib/types/client/FileTree.d.ts +36 -0
  20. package/lib/types/client/GitView.d.ts +8 -0
  21. package/lib/types/client/OrphanedTab.d.ts +11 -0
  22. package/lib/types/client/PdfView.d.ts +6 -0
  23. package/lib/types/client/RenderBoundary.d.ts +32 -0
  24. package/lib/types/client/SandboxStatusBar.d.ts +10 -0
  25. package/lib/types/client/SideCardSection.d.ts +74 -0
  26. package/lib/types/client/SideChatView.d.ts +16 -0
  27. package/lib/types/client/Sidebar.d.ts +6 -0
  28. package/lib/types/client/SubagentView.d.ts +16 -0
  29. package/lib/types/client/TabBar.d.ts +43 -0
  30. package/lib/types/client/TerminalView.d.ts +24 -0
  31. package/lib/types/client/TextEditor.d.ts +10 -0
  32. package/lib/types/client/TreePanel.d.ts +23 -0
  33. package/lib/types/client/UploadOverlay.d.ts +20 -0
  34. package/lib/types/client/add-plugin-modal.d.ts +15 -0
  35. package/lib/types/client/api.d.ts +268 -0
  36. package/lib/types/client/binary-download.d.ts +12 -0
  37. package/lib/types/client/breakpoints.d.ts +12 -0
  38. package/lib/types/client/browser.d.ts +50 -0
  39. package/lib/types/client/builtins/index.d.ts +18 -0
  40. package/lib/types/client/builtins/tabs.d.ts +11 -0
  41. package/lib/types/client/builtins/viewers.d.ts +3 -0
  42. package/lib/types/client/chunk-loader.d.ts +124 -0
  43. package/lib/types/client/chunks/editor.d.ts +9 -0
  44. package/lib/types/client/chunks/mermaid.d.ts +10 -0
  45. package/lib/types/client/chunks/terminal.d.ts +9 -0
  46. package/lib/types/client/cm-themes.d.ts +24 -0
  47. package/lib/types/client/conversation-draft.d.ts +14 -0
  48. package/lib/types/client/desktop-env.d.ts +35 -0
  49. package/lib/types/client/editable-state.d.ts +27 -0
  50. package/lib/types/client/editor-load.d.ts +66 -0
  51. package/lib/types/client/frame-batcher.d.ts +24 -0
  52. package/lib/types/client/icons.d.ts +57 -0
  53. package/lib/types/client/image-types.d.ts +3 -0
  54. package/lib/types/client/ime-guard.d.ts +36 -0
  55. package/lib/types/client/index.d.ts +19 -0
  56. package/lib/types/client/intercept.d.ts +33 -0
  57. package/lib/types/client/lang.d.ts +12 -0
  58. package/lib/types/client/lazy-chunk.d.ts +25 -0
  59. package/lib/types/client/link-intercept.d.ts +42 -0
  60. package/lib/types/client/locales.d.ts +366 -0
  61. package/lib/types/client/mermaid-blocks.d.ts +41 -0
  62. package/lib/types/client/mermaid-sanitize.d.ts +2 -0
  63. package/lib/types/client/mermaid.d.ts +12 -0
  64. package/lib/types/client/open-when-sized.d.ts +20 -0
  65. package/lib/types/client/open-with-settings.d.ts +4 -0
  66. package/lib/types/client/open-with.d.ts +87 -0
  67. package/lib/types/client/openpath-intercept.d.ts +41 -0
  68. package/lib/types/client/paths.d.ts +35 -0
  69. package/lib/types/client/pdf-types.d.ts +2 -0
  70. package/lib/types/client/plugin-settings.d.ts +8 -0
  71. package/lib/types/client/plugins-shared.d.ts +27 -0
  72. package/lib/types/client/plugins-tabs.d.ts +3 -0
  73. package/lib/types/client/plugins-viewers.d.ts +3 -0
  74. package/lib/types/client/prefs.d.ts +41 -0
  75. package/lib/types/client/produced-files.d.ts +23 -0
  76. package/lib/types/client/selection-payload.d.ts +27 -0
  77. package/lib/types/client/service.d.ts +440 -0
  78. package/lib/types/client/settings-nav-icon.d.ts +19 -0
  79. package/lib/types/client/shell-presets.d.ts +48 -0
  80. package/lib/types/client/sidechat-transcript.d.ts +103 -0
  81. package/lib/types/client/split-pane.d.ts +30 -0
  82. package/lib/types/client/state.d.ts +359 -0
  83. package/lib/types/client/subagent-detect.d.ts +54 -0
  84. package/lib/types/client/subagent-jobs.d.ts +63 -0
  85. package/lib/types/client/tab-content-memo.d.ts +33 -0
  86. package/lib/types/client/terminal-font.d.ts +20 -0
  87. package/lib/types/client/theme.d.ts +45 -0
  88. package/lib/types/client/titlebar-strip.d.ts +23 -0
  89. package/lib/types/client/upload.d.ts +69 -0
  90. package/lib/types/client/wco.d.ts +47 -0
  91. package/lib/types/config.d.ts +64 -0
  92. package/lib/types/context-types.d.ts +603 -0
  93. package/lib/types/fs-operations.d.ts +28 -0
  94. package/lib/types/fs-search.d.ts +24 -0
  95. package/lib/types/fs-tree.d.ts +51 -0
  96. package/lib/types/git.d.ts +82 -0
  97. package/lib/types/html-route.d.ts +59 -0
  98. package/lib/types/index.d.ts +47 -0
  99. package/lib/types/invariant.d.ts +15 -0
  100. package/lib/types/jobs-routes.d.ts +45 -0
  101. package/lib/types/open-external.d.ts +24 -0
  102. package/lib/types/prefs-shared.d.ts +225 -0
  103. package/lib/types/pty-deps.d.ts +78 -0
  104. package/lib/types/pty-manager.d.ts +168 -0
  105. package/lib/types/sidechat-core.d.ts +172 -0
  106. package/lib/types/sidechat-routes.d.ts +30 -0
  107. package/lib/types/subagent-activity.d.ts +44 -0
  108. package/lib/types/subagent-live-route.d.ts +44 -0
  109. package/lib/types/tools.d.ts +31 -0
  110. package/lib/types/trust-fence.d.ts +24 -0
  111. package/lib/types/wire.d.ts +38 -0
  112. package/package.json +173 -0
  113. package/scripts/install.ps1 +289 -0
  114. package/scripts/install.sh +287 -0
  115. package/src/agent-pty.ts +527 -0
  116. package/src/browser-probe.ts +26 -0
  117. package/src/bundle-route.ts +129 -0
  118. package/src/client/BrowserView.tsx +253 -0
  119. package/src/client/DiffTab.tsx +110 -0
  120. package/src/client/DiffView.tsx +305 -0
  121. package/src/client/EditorHost.tsx +525 -0
  122. package/src/client/FileTree.tsx +653 -0
  123. package/src/client/GitView.tsx +558 -0
  124. package/src/client/OrphanedTab.tsx +27 -0
  125. package/src/client/PdfView.tsx +110 -0
  126. package/src/client/RenderBoundary.tsx +49 -0
  127. package/src/client/SandboxStatusBar.tsx +60 -0
  128. package/src/client/SideCardSection.module.css +960 -0
  129. package/src/client/SideCardSection.tsx +1152 -0
  130. package/src/client/SideChatView.module.css +437 -0
  131. package/src/client/SideChatView.tsx +644 -0
  132. package/src/client/Sidebar.tsx +1148 -0
  133. package/src/client/SubagentView.module.css +547 -0
  134. package/src/client/SubagentView.tsx +883 -0
  135. package/src/client/TabBar.tsx +305 -0
  136. package/src/client/TerminalView.tsx +383 -0
  137. package/src/client/TextEditor.tsx +500 -0
  138. package/src/client/TreePanel.tsx +273 -0
  139. package/src/client/UploadOverlay.tsx +62 -0
  140. package/src/client/add-plugin-modal.tsx +199 -0
  141. package/src/client/api.ts +335 -0
  142. package/src/client/binary-download.tsx +23 -0
  143. package/src/client/breakpoints.ts +51 -0
  144. package/src/client/browser.ts +119 -0
  145. package/src/client/builtins/index.ts +37 -0
  146. package/src/client/builtins/tabs.tsx +331 -0
  147. package/src/client/builtins/viewers.tsx +125 -0
  148. package/src/client/chunk-loader.ts +351 -0
  149. package/src/client/chunks/editor.tsx +9 -0
  150. package/src/client/chunks/mermaid.tsx +10 -0
  151. package/src/client/chunks/terminal.tsx +9 -0
  152. package/src/client/cm-themes.ts +129 -0
  153. package/src/client/conversation-draft.ts +29 -0
  154. package/src/client/css-modules.d.ts +5 -0
  155. package/src/client/desktop-env.ts +72 -0
  156. package/src/client/editable-state.ts +70 -0
  157. package/src/client/editor-load.ts +92 -0
  158. package/src/client/frame-batcher.ts +56 -0
  159. package/src/client/icons.tsx +161 -0
  160. package/src/client/image-types.ts +8 -0
  161. package/src/client/ime-guard.ts +47 -0
  162. package/src/client/index.tsx +369 -0
  163. package/src/client/intercept.tsx +110 -0
  164. package/src/client/lang.ts +103 -0
  165. package/src/client/layout.css +94 -0
  166. package/src/client/lazy-chunk.tsx +89 -0
  167. package/src/client/link-intercept.ts +73 -0
  168. package/src/client/locales.ts +734 -0
  169. package/src/client/mermaid-blocks.ts +110 -0
  170. package/src/client/mermaid-sanitize.ts +93 -0
  171. package/src/client/mermaid.tsx +401 -0
  172. package/src/client/open-when-sized.ts +43 -0
  173. package/src/client/open-with-settings.tsx +135 -0
  174. package/src/client/open-with.ts +221 -0
  175. package/src/client/openpath-intercept.ts +62 -0
  176. package/src/client/paths.ts +47 -0
  177. package/src/client/pdf-types.ts +4 -0
  178. package/src/client/plugin-settings.ts +43 -0
  179. package/src/client/plugins-shared.ts +29 -0
  180. package/src/client/plugins-tabs.ts +87 -0
  181. package/src/client/plugins-viewers.ts +30 -0
  182. package/src/client/prefs.ts +207 -0
  183. package/src/client/produced-files.ts +91 -0
  184. package/src/client/selection-payload.ts +86 -0
  185. package/src/client/service.ts +838 -0
  186. package/src/client/settings-nav-icon.ts +45 -0
  187. package/src/client/shell-presets.ts +83 -0
  188. package/src/client/sidebar.module.css +2577 -0
  189. package/src/client/sidechat-transcript.ts +321 -0
  190. package/src/client/split-pane.tsx +322 -0
  191. package/src/client/state.ts +1175 -0
  192. package/src/client/subagent-detect.ts +137 -0
  193. package/src/client/subagent-jobs.ts +161 -0
  194. package/src/client/tab-content-memo.ts +46 -0
  195. package/src/client/terminal-font.ts +28 -0
  196. package/src/client/theme.ts +110 -0
  197. package/src/client/titlebar-strip.ts +37 -0
  198. package/src/client/upload.ts +187 -0
  199. package/src/client/wco.ts +120 -0
  200. package/src/config.ts +155 -0
  201. package/src/context-types.ts +610 -0
  202. package/src/fs-operations.ts +99 -0
  203. package/src/fs-search.ts +86 -0
  204. package/src/fs-tree.ts +158 -0
  205. package/src/git.ts +244 -0
  206. package/src/html-route.ts +106 -0
  207. package/src/index.ts +1132 -0
  208. package/src/invariant.ts +32 -0
  209. package/src/jobs-routes.ts +257 -0
  210. package/src/open-external.ts +90 -0
  211. package/src/prefs-shared.ts +268 -0
  212. package/src/pty-deps.ts +240 -0
  213. package/src/pty-manager.ts +376 -0
  214. package/src/sidechat-core.ts +468 -0
  215. package/src/sidechat-routes.ts +344 -0
  216. package/src/subagent-activity.ts +91 -0
  217. package/src/subagent-live-route.ts +93 -0
  218. package/src/tools.ts +479 -0
  219. package/src/trust-fence.ts +77 -0
  220. package/src/wire.ts +100 -0
package/package.json ADDED
@@ -0,0 +1,173 @@
1
+ {
2
+ "name": "@keith9681/dsh-sidebar",
3
+ "version": "0.15.2",
4
+ "description": "DSH web plugin: a VSCode-like right sidebar (explorer / editor / terminal / git / browser), isolated per conversation session. Exposes a service for other plugins to register sidebar tabs and file viewers. Fork of dsh-better-sidebar with read-only-by-default editing and no bottom panel.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://git.rhett.cloud/keith/dsh-sidebar"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "main": "lib/index.js",
14
+ "types": "lib/types/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./lib/types/index.d.ts",
18
+ "default": "./lib/index.js"
19
+ },
20
+ "./invariant": {
21
+ "types": "./lib/types/invariant.d.ts",
22
+ "default": "./lib/invariant.js"
23
+ },
24
+ "./client": {
25
+ "types": "./lib/types/client/index.d.ts",
26
+ "default": "./lib/client.js"
27
+ },
28
+ "./client/service": {
29
+ "types": "./lib/types/client/service.d.ts",
30
+ "default": "./lib/client.js"
31
+ },
32
+ "./client/api": {
33
+ "types": "./lib/types/client/service.d.ts",
34
+ "default": "./lib/client.js"
35
+ },
36
+ "./src/*": "./src/*",
37
+ "./package.json": "./package.json"
38
+ },
39
+ "engines": {
40
+ "node": ">=20"
41
+ },
42
+ "dsh": {
43
+ "bundle": {
44
+ "patch": "./cordis.patch.yml"
45
+ },
46
+ "client": {
47
+ "inject": [
48
+ "@deepseek-ai/dsh-client-runtime",
49
+ "@deepseek-ai/dsh-client-locale",
50
+ "@deepseek-ai/dsh-client-ui-slots",
51
+ "@deepseek-ai/dsh-client-ui-conversation",
52
+ "@deepseek-ai/dsh-client-modules"
53
+ ],
54
+ "platform": "web"
55
+ }
56
+ },
57
+ "files": [
58
+ "lib/index.js",
59
+ "lib/invariant.js",
60
+ "lib/client.js",
61
+ "lib/client-registry.js",
62
+ "lib/client-terminal.js",
63
+ "lib/client-editor.js",
64
+ "lib/client-mermaid.js",
65
+ "lib/types/**/*.d.ts",
66
+ "src",
67
+ "scripts/install.sh",
68
+ "scripts/install.ps1",
69
+ "cordis.patch.yml",
70
+ "README.md",
71
+ "README_EN.md",
72
+ "LICENSE"
73
+ ],
74
+ "scripts": {
75
+ "build": "rm -rf lib && tsc -p tsconfig.build.json && tsdown",
76
+ "prepublishOnly": "pnpm build",
77
+ "typecheck": "tsc --noEmit",
78
+ "bundle": "tsdown",
79
+ "watch": "tsdown --watch",
80
+ "prepare": "tsdown",
81
+ "test": "vitest run",
82
+ "test:mount": "bash scripts/e2e-mount.sh",
83
+ "check:consumer-types": "bash scripts/check-consumer-types.sh"
84
+ },
85
+ "license": "MIT",
86
+ "peerDependencies": {
87
+ "@deepseek-ai/cordis": "^4.0.1",
88
+ "@deepseek-ai/dsh-agent": "^0.1.0-rc.8",
89
+ "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.8",
90
+ "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.8",
91
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.8",
92
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.8",
93
+ "@deepseek-ai/dsh-client-ui-settings": "^0.1.0-rc.8",
94
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.8",
95
+ "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.8",
96
+ "@deepseek-ai/dsh-invariants": "^0.1.0-rc.8",
97
+ "@deepseek-ai/dsh-llm": "^0.1.0-rc.8",
98
+ "@deepseek-ai/dsh-session": "^0.1.0-rc.8",
99
+ "@deepseek-ai/dsh-settings": "^0.1.0-rc.8",
100
+ "@deepseek-ai/dsh-subagent": "^0.1.0-rc.8",
101
+ "@deepseek-ai/dsh-tools": "^0.1.0-rc.8",
102
+ "cordis": "^4.0.0-rc.8",
103
+ "react": "^18.2.0",
104
+ "react-dom": "^18.2.0"
105
+ },
106
+ "peerDependenciesMeta": {
107
+ "cordis": {
108
+ "optional": true
109
+ }
110
+ },
111
+ "dependencies": {
112
+ "@codemirror/commands": "^6.10.4",
113
+ "@codemirror/lang-cpp": "^6.0.3",
114
+ "@codemirror/lang-css": "^6.3.1",
115
+ "@codemirror/lang-go": "^6.0.1",
116
+ "@codemirror/lang-html": "^6.4.12",
117
+ "@codemirror/lang-java": "^6.0.2",
118
+ "@codemirror/lang-javascript": "^6.2.5",
119
+ "@codemirror/lang-json": "^6.0.2",
120
+ "@codemirror/lang-markdown": "^6.5.2",
121
+ "@codemirror/lang-php": "^6.0.2",
122
+ "@codemirror/lang-python": "^6.2.1",
123
+ "@codemirror/lang-rust": "^6.0.2",
124
+ "@codemirror/lang-sql": "^6.10.0",
125
+ "@codemirror/lang-xml": "^6.1.0",
126
+ "@codemirror/lang-yaml": "^6.1.3",
127
+ "@codemirror/language": "^6.12.4",
128
+ "@codemirror/legacy-modes": "^6.5.3",
129
+ "@codemirror/search": "^6.7.1",
130
+ "@codemirror/state": "^6.7.1",
131
+ "@codemirror/view": "^6.43.8",
132
+ "@lezer/highlight": "^1.2.3",
133
+ "clsx": "^2.1.1",
134
+ "mermaid": "^11.16.1",
135
+ "node-pty": "^1.1.0",
136
+ "react-icons": "5.7.0",
137
+ "rxjs": "^7.8.2",
138
+ "schemastery": "^3.18.0",
139
+ "ws": "^8.18.0"
140
+ },
141
+ "devDependencies": {
142
+ "@cordisjs/plugin-loader": "^1.0.0-rc.5",
143
+ "@deepseek-ai/dsh-agent": "0.1.1-rc.1",
144
+ "@deepseek-ai/dsh-client-locale": "0.1.1-rc.1",
145
+ "@deepseek-ai/dsh-client-runtime": "0.1.1-rc.1",
146
+ "@deepseek-ai/dsh-client-ui-conversation": "0.1.1-rc.1",
147
+ "@deepseek-ai/dsh-client-ui-primitives": "0.1.1-rc.1",
148
+ "@deepseek-ai/dsh-client-ui-settings": "0.1.1-rc.1",
149
+ "@deepseek-ai/dsh-client-ui-slots": "0.1.1-rc.1",
150
+ "@deepseek-ai/dsh-host-webserver": "0.1.1-rc.1",
151
+ "@deepseek-ai/dsh-invariants": "0.1.1-rc.1",
152
+ "@deepseek-ai/dsh-llm": "0.1.1-rc.1",
153
+ "@deepseek-ai/dsh-session": "0.1.1-rc.1",
154
+ "@deepseek-ai/dsh-settings": "0.1.1-rc.1",
155
+ "@deepseek-ai/dsh-subagent": "0.1.1-rc.1",
156
+ "@deepseek-ai/dsh-tools": "0.1.1-rc.1",
157
+ "@playwright/test": "^1.62.1",
158
+ "@types/node": "^24.0.0",
159
+ "@types/react": "~18.3.1",
160
+ "@types/react-dom": "~18.3.1",
161
+ "@types/ws": "^8.5.10",
162
+ "@xterm/addon-fit": "^0.11.0",
163
+ "@xterm/xterm": "^5.5.0",
164
+ "cordis": "^4.0.0-rc.8",
165
+ "jsdom": "^29.1.1",
166
+ "lightningcss": "^1.32.0",
167
+ "react": "^18.2.0",
168
+ "react-dom": "18.2.0",
169
+ "tsdown": "^0.22.2",
170
+ "typescript": "^5.6.0",
171
+ "vitest": "^4.1.8"
172
+ }
173
+ }
@@ -0,0 +1,289 @@
1
+ ## =============================================================================
2
+ # dsh-better-sidebar 一键安装脚本(官方 CLI 方式,Windows PowerShell 5.1+ / pwsh)
3
+ #
4
+ # 通过 DSH 官方插件命令安装 npm 包并自动挂载:
5
+ # dsh plugin --profile web add dsh-better-sidebar@<version>
6
+ #
7
+ # 包内声明了 dsh.bundle.patch(cordis.patch.yml):CLI 的 bundle 协调会把它
8
+ # 自动加进 profile 的 dsh.profile.bundles,下次启动即挂载——无需手动写
9
+ # cordis.patch.yml 挂载行。符合仓库硬约束:不修改 DSH 源码,插件永远作为
10
+ # 独立包被 profile 引用。
11
+ #
12
+ # 用法(任选其一):
13
+ # # 默认最新版
14
+ # irm https://raw.githubusercontent.com/omdsh-dev/DSH-better-sidebar/main/scripts/install.ps1 | iex
15
+ # # 指定版本 / 装完重启
16
+ # & ([scriptblock]::Create((irm 'https://raw.githubusercontent.com/omdsh-dev/DSH-better-sidebar/main/scripts/install.ps1'))) -Version 0.10.2 -Restart
17
+ # # 本地保存后运行
18
+ # powershell -ExecutionPolicy Bypass -File install.ps1 -Version 0.10.2 -DryRun
19
+ # # 修复 node-pty 依赖(终端提示「node-pty 加载失败」时用,见 issue #140)
20
+ # powershell -ExecutionPolicy Bypass -File install.ps1 -Repair
21
+ #
22
+ # 参数:
23
+ # -Version npm 版本号/范围,缺省 latest(自动解析为最新)。
24
+ # -Repair 修复模式:不重装插件,只确保 profile 的 pnpm-workspace.yaml
25
+ # 放行 node-pty 构建脚本,然后重跑 pnpm install + pnpm rebuild
26
+ # node-pty。
27
+ # -Profile 目标 profile 名(缺省 web);安装与修复模式均适用。
28
+ # -Restart 装完后尝试 `pm2 restart dsh-web`(无 pm2 时仅提示)。会断开当前页面会话。
29
+ # -DryRun 只打印将要执行的操作,不写任何文件。
30
+ #
31
+ # 环境变量(均可省略):
32
+ # DSH_HOME 默认 %USERPROFILE%\.dsh
33
+ # REGISTRY 默认 https://registry.npmjs.org
34
+ # DSH_CMD 默认优先 PATH 上的 dsh,缺省回退 npx -y --package @deepseek-ai/dsh
35
+ #
36
+ # 说明:
37
+ # - pnpm 11 的 strict-dep-builds 会拦截 node-pty/protobufjs 的构建脚本并使
38
+ # `dsh plugin add` 非零退出。脚本会先把这两个构建许可写进 profile 的
39
+ # pnpm-workspace.yaml(幂等),保证 CLI 一步成功。
40
+ # - pnpm 11 的 minimumReleaseAge 会拒绝发布 <24h 的新版本。脚本会预写
41
+ # minimumReleaseAgeExclude(幂等),放行本插件,避免"重跑一次才成功"。
42
+ # - 老版本(<0.10.2)用手动挂载行,bundle 通道激活后需移除,否则双挂载。
43
+ # 脚本会幂等移除 better-sidebar 挂载行。
44
+ # =============================================================================
45
+ param(
46
+ [string]$Version = '',
47
+ [switch]$Restart,
48
+ [switch]$DryRun,
49
+ [switch]$Repair,
50
+ [string]$Profile = 'web'
51
+ )
52
+
53
+ $PKG = 'dsh-better-sidebar'
54
+ $REGISTRY = if ($env:REGISTRY) { $env:REGISTRY } else { 'https://registry.npmjs.org' }
55
+
56
+ # DSH_HOME:DSH_HOME 环境变量 > %USERPROFILE% > $HOME
57
+ if ($env:DSH_HOME) {
58
+ $DSH_HOME = $env:DSH_HOME
59
+ } elseif ($env:USERPROFILE) {
60
+ $DSH_HOME = Join-Path $env:USERPROFILE '.dsh'
61
+ } else {
62
+ $DSH_HOME = Join-Path $HOME '.dsh'
63
+ }
64
+ $PROFILE_DIR = Join-Path $DSH_HOME "profiles\$Profile"
65
+ $WS_YML = Join-Path $PROFILE_DIR 'pnpm-workspace.yaml'
66
+ $PATCH_YML = Join-Path $PROFILE_DIR 'cordis.patch.yml'
67
+
68
+ function Say([string]$m) { Write-Host "[install] $m" -ForegroundColor Green }
69
+ function Warn([string]$m) { Write-Host "[warn] $m" -ForegroundColor Yellow }
70
+ function Die([string]$m) { Write-Host "[error] $m" -ForegroundColor Red; exit 1 }
71
+
72
+ # 解析版本 -> npm spec("x.y.z" / "^x.y.z" / latest)
73
+ function Resolve-Spec {
74
+ param([string]$Given)
75
+ if ([string]::IsNullOrWhiteSpace($Given) -or $Given -eq 'latest') {
76
+ $v = $null
77
+ foreach ($tool in @('npm', 'pnpm')) {
78
+ if (Get-Command $tool -ErrorAction SilentlyContinue) {
79
+ $v = (& $tool view $PKG version "--registry=$REGISTRY" 2>$null | Select-Object -Last 1)
80
+ if ($v) { break }
81
+ }
82
+ }
83
+ if ($v) { return ([string]$v).Trim() }
84
+ Warn '无法联网解析最新版本(npm/pnpm 查询失败),回退为 latest,由 pnpm 直接解析。'
85
+ Warn '若已知版本号,可显式传入:-Version 0.10.2'
86
+ return 'latest'
87
+ }
88
+ return $Given
89
+ }
90
+
91
+ # 组装 dsh CLI:优先 PATH 上的 dsh,缺省 npx 拉官方包
92
+ function Get-DshCli {
93
+ if ($env:DSH_CMD) { return $env:DSH_CMD }
94
+ if (Get-Command dsh -ErrorAction SilentlyContinue) { return 'dsh' }
95
+ if (Get-Command npx -ErrorAction SilentlyContinue) { return 'npx' }
96
+ return $null
97
+ }
98
+
99
+ # 步骤 1(安装与修复共用):预写 workspace 设置(幂等),保证 pnpm 不拦截
100
+ # node-pty/protobufjs 构建脚本、放行本插件新版本
101
+ function Ensure-WorkspaceSettings {
102
+ $wsScript = @'
103
+ const fs = require("fs");
104
+ const p = process.argv[2];
105
+ let t = fs.readFileSync(p, "utf8");
106
+ const before = t;
107
+ t = t.replace(/^(\s*)(node-pty|protobufjs):.*$/gm, "$1$2: true");
108
+ if (!/^\s*allowBuilds:\s*$/m.test(t)) {
109
+ t += "\nallowBuilds:\n node-pty: true\n protobufjs: true\n";
110
+ } else {
111
+ for (const k of ["node-pty", "protobufjs"]) {
112
+ if (!new RegExp("^\\s*" + k + ":\\s*true\\s*$", "m").test(t)) {
113
+ t = t.replace(/^(\s*allowBuilds:\s*)$/m, "$1\n " + k + ": true");
114
+ }
115
+ }
116
+ }
117
+ if (!/^\s*-\s+dsh-better-sidebar\s*$/m.test(t)) {
118
+ if (/^\s*minimumReleaseAgeExclude:\s*$/m.test(t)) {
119
+ t = t.replace(/^(\s*minimumReleaseAgeExclude:\s*)$/m, "$1\n - dsh-better-sidebar");
120
+ } else {
121
+ t += "\nminimumReleaseAgeExclude:\n - dsh-better-sidebar\n";
122
+ }
123
+ }
124
+ if (t !== before) fs.writeFileSync(p, t);
125
+ console.log(t === before ? "unchanged" : "updated");
126
+ '@
127
+ # PowerShell 5.1 把含内嵌双引号的多行 JS 作为参数传给 `node -e` 时,引号会被
128
+ # Windows 命令行解析吞掉,导致 JS 语法错误(Expected ',', got ':')。
129
+ # 改用临时文件方式,兼容 PS 5.1 与 pwsh 7。
130
+ $wsJs = Join-Path $env:TEMP ("dshbs-ws-" + [guid]::NewGuid().ToString("N") + ".js")
131
+ Set-Content -LiteralPath $wsJs -Value $wsScript -Encoding UTF8
132
+ $wsOut = node $wsJs "$WS_YML" 2>&1
133
+ $wsCode = $LASTEXITCODE
134
+ Remove-Item -LiteralPath $wsJs -Force -ErrorAction SilentlyContinue
135
+ $wsResult = (($wsOut | Out-String)).Trim()
136
+ if ($wsCode -ne 0) { Die "处理 $WS_YML 失败(node 退出码 $wsCode):$wsResult" }
137
+ if ($wsResult -eq 'updated') {
138
+ Say "已确保 $WS_YML:allowBuilds(node-pty/protobufjs: true)+ minimumReleaseAgeExclude($PKG)"
139
+ } else {
140
+ Say 'workspace 设置已就绪,跳过'
141
+ }
142
+ }
143
+
144
+ # 前置校验
145
+ if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
146
+ Die '未找到 node(DSH 运行需要 Node.js >= 20),请先安装 Node.js 并加入 PATH。'
147
+ }
148
+ if (-not (Test-Path $PROFILE_DIR)) {
149
+ Die "找不到 profile 目录:$PROFILE_DIR(请先安装并运行过一次 dsh web)"
150
+ }
151
+ if (-not (Test-Path $WS_YML)) {
152
+ Die "找不到 $WS_YML(请先初始化 $Profile profile)"
153
+ }
154
+
155
+ # ── 修复模式(issue #140):不重装插件,只修复 node-pty 依赖 ────────────
156
+ # 终端提示「node-pty 加载失败」时运行:确保 allowBuilds 后重跑
157
+ # pnpm install + pnpm rebuild node-pty(重放被 pnpm 11 拦截的构建脚本)。
158
+ if ($Repair) {
159
+ if ($DryRun) {
160
+ Say "[dry-run] 修复:确保 $WS_YML 含 allowBuilds(node-pty: true)"
161
+ Say "[dry-run] 修复:cd $PROFILE_DIR; pnpm install; pnpm rebuild node-pty"
162
+ exit 0
163
+ }
164
+ Say "修复模式:重装 node-pty(profile: $Profile,$PROFILE_DIR)..."
165
+ Ensure-WorkspaceSettings
166
+ Push-Location $PROFILE_DIR
167
+ try {
168
+ pnpm install
169
+ if ($LASTEXITCODE -ne 0) { Die "pnpm install 失败(退出码 $LASTEXITCODE)。请确认 pnpm 在 PATH 上、网络可用,然后重试。" }
170
+ pnpm rebuild node-pty
171
+ if ($LASTEXITCODE -ne 0) { Die "pnpm rebuild node-pty 失败(退出码 $LASTEXITCODE)。请确认 pnpm 在 PATH 上,然后重试。" }
172
+ } finally {
173
+ Pop-Location
174
+ }
175
+ Say '修复完成:node-pty 已重装(与 DSH 核心保持同一版本)。请重启 DSH 后重试终端。'
176
+ exit 0
177
+ }
178
+
179
+ $SPEC = Resolve-Spec $Version
180
+ $CLI = Get-DshCli
181
+ if (-not $CLI) {
182
+ Die '未找到 dsh 或 npx。请先安装 DSH(并确保 Node/npm 可用),或用 DSH_CMD 指定。'
183
+ }
184
+ Say "目标:$CLI plugin --profile $Profile add $PKG@$SPEC(profile: $PROFILE_DIR)"
185
+
186
+ if ($DryRun) {
187
+ Say "[dry-run] 步骤 1:确保 $WS_YML 含 allowBuilds(node-pty/protobufjs: true)与 minimumReleaseAgeExclude($PKG)"
188
+ Say "[dry-run] 步骤 2:执行 $CLI plugin --profile $Profile add $PKG@$SPEC(安装 + bundle 自动注册)"
189
+ Say "[dry-run] 步骤 3:校验 dsh.profile.bundles 含 $PKG"
190
+ Say "[dry-run] 步骤 4:幂等移除 $PATCH_YML 里旧的 better-sidebar 手动挂载行(避免双挂载)"
191
+ if ($Restart) { Say '[dry-run] 步骤 5:pm2 restart dsh-web' } else { Say '[dry-run] 步骤 5:提示用户手动重启 DSH' }
192
+ exit 0
193
+ }
194
+
195
+ # 步骤 1:预写 workspace 设置(幂等),保证 pnpm 不拦截构建、放行本插件新版本
196
+ Ensure-WorkspaceSettings
197
+
198
+ # 步骤 2:官方 CLI 安装 + bundle 自动注册(含挂载)
199
+ if ($CLI -eq 'dsh') {
200
+ $cliArgs = @('plugin', '--profile', $Profile, 'add', "$PKG@$SPEC")
201
+ } else {
202
+ $cliArgs = @('-y', '--package', '@deepseek-ai/dsh', 'dsh', 'plugin', '--profile', $Profile, 'add', "$PKG@$SPEC")
203
+ }
204
+ Say "执行 $CLI plugin --profile $Profile add $PKG@$SPEC ..."
205
+ $addOut = & $CLI @cliArgs 2>&1
206
+ $addCode = $LASTEXITCODE
207
+ $addOut | ForEach-Object { $_ }
208
+ if ($addCode -ne 0) {
209
+ Warn 'dsh plugin add 失败。已预写 allowBuilds 与 minimumReleaseAgeExclude,仍失败的可能原因:'
210
+ Warn ' - 网络/登录问题:npm registry 不可达或需要登录。'
211
+ Warn " - 依赖安装冲突:可手动重试 cd $PROFILE_DIR; pnpm install。"
212
+ exit 1
213
+ }
214
+
215
+ # 步骤 3:校验 bundle 已注册(挂载生效的判据)
216
+ $pkgJson = Get-Content -Raw (Join-Path $PROFILE_DIR 'package.json') | ConvertFrom-Json
217
+ $bundles = $pkgJson.dsh.profile.bundles
218
+ if ($bundles -notcontains $PKG) {
219
+ Warn 'dsh-better-sidebar 未出现在 dsh.profile.bundles 中——挂载未注册。'
220
+ Warn "若上面的 pnpm 输出提示 ignored build scripts,请确认 $WS_YML 的 allowBuilds 后重跑本脚本。"
221
+ exit 1
222
+ }
223
+ Say "bundle 已注册:dsh.profile.bundles 包含 $PKG(下次启动自动挂载)"
224
+
225
+ # 步骤 4:幂等移除旧的 manual 挂载行(避免与 bundle 双挂载)
226
+ $mountScript = @'
227
+ const fs = require("fs");
228
+ const p = process.argv[2];
229
+ const lines = fs.readFileSync(p, "utf8").split("\n");
230
+ const out = [];
231
+ let i = 0;
232
+ let removed = false;
233
+ while (i < lines.length) {
234
+ const line = lines[i];
235
+ if (/^[ \t]*- insert:\s*$/.test(line)) {
236
+ const block = [line];
237
+ let j = i + 1;
238
+ while (j < lines.length && lines[j].trim() !== "" && !/^-\s/.test(lines[j])) {
239
+ block.push(lines[j]);
240
+ j++;
241
+ }
242
+ if (block.some((l) => /id:\s*better-sidebar\b/.test(l))) {
243
+ while (out.length && /^[ \t]*#/.test(out[out.length - 1])) out.pop();
244
+ i = j;
245
+ removed = true;
246
+ continue;
247
+ }
248
+ }
249
+ out.push(line);
250
+ i++;
251
+ }
252
+ if (!removed) {
253
+ console.log("none");
254
+ } else {
255
+ const t = out.join("\n").replace(/\n{3,}/g, "\n\n");
256
+ fs.writeFileSync(p, t);
257
+ console.log("removed");
258
+ }
259
+ '@
260
+ $mountJs = Join-Path $env:TEMP ("dshbs-mount-" + [guid]::NewGuid().ToString("N") + ".js")
261
+ Set-Content -LiteralPath $mountJs -Value $mountScript -Encoding UTF8
262
+ $mountOut = node $mountJs "$PATCH_YML" 2>&1
263
+ $mountCode = $LASTEXITCODE
264
+ Remove-Item -LiteralPath $mountJs -Force -ErrorAction SilentlyContinue
265
+ $mountResult = (($mountOut | Out-String)).Trim()
266
+ if ($mountCode -ne 0) { Die "处理 $PATCH_YML 失败(node 退出码 $mountCode):$mountResult" }
267
+ if ($mountResult -eq 'removed') {
268
+ Say "已从 $PATCH_YML 移除旧的 better-sidebar 手动挂载行(bundle 通道接管挂载)"
269
+ } else {
270
+ Say '无旧手动挂载行,跳过'
271
+ }
272
+
273
+ Say "安装完成:$PKG@$SPEC"
274
+
275
+ # 步骤 5:重启提示
276
+ if ($Restart) {
277
+ if (Get-Command pm2 -ErrorAction SilentlyContinue) {
278
+ Say '重启 dsh-web(pm2)...'
279
+ pm2 restart dsh-web
280
+ if ($LASTEXITCODE -ne 0) { Warn 'pm2 restart 失败,请手动重启 DSH' }
281
+ } else {
282
+ Warn '未找到 pm2,请手动重启 DSH(如:pm2 restart dsh-web 或 dsh web)'
283
+ }
284
+ } else {
285
+ Say '下一步:重启 DSH 并硬刷新(Ctrl+Shift+R / Cmd+Shift+R)使新副本生效。'
286
+ if (Get-Command pm2 -ErrorAction SilentlyContinue) {
287
+ Say '本机可用:pm2 restart dsh-web(会短暂断开当前页面会话)'
288
+ }
289
+ }