pi-web-ui 0.114.1 → 0.114.3

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 (130) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +187 -187
  3. package/README.zh-CN.md +227 -227
  4. package/README.zh-TW.md +227 -227
  5. package/bin/device-hub-cli.mjs +577 -577
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -9
  8. package/bin/pi-web-ui.mjs +4081 -4081
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +88 -15
  12. package/dist/server/attachments.js +6 -6
  13. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  14. package/dist/server/communicate-tool.js +37 -11
  15. package/dist/server/compaction-instructions.js +8 -8
  16. package/dist/server/context-usage.js +105 -0
  17. package/dist/server/device-center/desktop-page.js +228 -228
  18. package/dist/server/device-center/hub-page.js +64 -64
  19. package/dist/server/device-center/native-desktop/macos.js +190 -190
  20. package/dist/server/device-center/native-desktop/windows.js +116 -116
  21. package/dist/server/dsh/runtime/cordis.yml +1 -1
  22. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  23. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  24. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  25. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  26. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  27. package/dist/server/durable/durable-event-projector.js +19 -3
  28. package/dist/server/durable/durable-models.js +134 -65
  29. package/dist/server/eval-tool.js +135 -135
  30. package/dist/server/model-resolver.js +4 -1
  31. package/dist/server/patch-bash-process.js +89 -89
  32. package/dist/server/patch-tool.js +9 -9
  33. package/dist/server/patch-turn-end-boundary.js +3 -3
  34. package/dist/server/persona-chain.js +8 -8
  35. package/dist/server/protocol-version.js +1 -1
  36. package/dist/server/remote-ssh-service.js +39 -39
  37. package/dist/server/schedule-agent-tool.js +11 -6
  38. package/dist/server/scheduler-tasks.js +84 -2
  39. package/dist/server/scm-commitmsg.js +10 -10
  40. package/dist/server/setup-page.js +620 -620
  41. package/dist/server/universal/universal-session.js +19 -18
  42. package/dist/server/vision-bridge.js +18 -18
  43. package/docs/device-center.md +148 -148
  44. package/docs/device-desktop.md +48 -48
  45. package/docs/dsh-engine.md +493 -493
  46. package/extensions/webui.ts +335 -335
  47. package/package.json +1 -1
  48. package/plugin-sdk/README.md +174 -174
  49. package/plugin-sdk/client-utils.mjs +279 -279
  50. package/plugin-sdk/import-check.mjs +210 -210
  51. package/plugin-sdk/index.d.ts +698 -698
  52. package/plugin-sdk/index.mjs +696 -696
  53. package/plugin-sdk/package.json +13 -13
  54. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  55. package/themes/aetheris.css +501 -501
  56. package/themes/ayu-light.css +116 -116
  57. package/themes/bases/flow-base.css +1357 -1357
  58. package/themes/bases/obsidian-base.css +895 -895
  59. package/themes/bases/statusbar-flat-base.css +112 -112
  60. package/themes/bases/zhujian-base.css +688 -688
  61. package/themes/bases/zhupi-base.css +660 -660
  62. package/themes/catppuccin-latte.css +119 -119
  63. package/themes/catppuccin.css +116 -116
  64. package/themes/claude-code-dark.css +147 -147
  65. package/themes/codex.css +114 -114
  66. package/themes/cyberpunk.css +50 -50
  67. package/themes/dark-teal.css +264 -264
  68. package/themes/dazzle.css +38 -38
  69. package/themes/everforest-light.css +115 -115
  70. package/themes/flow-light.css +164 -164
  71. package/themes/flow.css +161 -161
  72. package/themes/geist.css +114 -114
  73. package/themes/gruvbox-light.css +115 -115
  74. package/themes/kanagawa-lotus.css +115 -115
  75. package/themes/md-preview.css +24 -24
  76. package/themes/mist.css +166 -166
  77. package/themes/nord.css +107 -107
  78. package/themes/one-dark.css +106 -106
  79. package/themes/paper.css +174 -174
  80. package/themes/rose-pine-dawn.css +114 -114
  81. package/themes/sakura.css +166 -166
  82. package/themes/solarized-light.css +114 -114
  83. package/themes/tokyo-night.css +115 -115
  84. package/themes/translucent.css +85 -85
  85. package/themes/transparent.css +116 -116
  86. package/themes/vs-code-dark.css +147 -147
  87. package/themes/wallpaper-flow.css +382 -382
  88. package/themes/wallpaper-obsidian.css +74 -74
  89. package/themes/white.css +164 -164
  90. package/themes/zhujian-dark.css +115 -115
  91. package/themes/zhujian.css +114 -114
  92. package/themes/zhupi-dark.css +115 -115
  93. package/themes/zhupi.css +114 -114
  94. package/web/dist/.build-assets.json +1 -1
  95. package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BvnUHjFe.js} +1 -1
  96. package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-DSC8ncW3.js} +1 -1
  97. package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-BSg9ghPV.js} +2 -2
  98. package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-DxW7C3Sz.js} +2 -2
  99. package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-Bmgr-Bwm.js} +1 -1
  100. package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-Cl9MBXaH.js} +1 -1
  101. package/web/dist/assets/{DeviceGroups-D2rogxEN.js → DeviceGroups-aeLD2msl.js} +1 -1
  102. package/web/dist/assets/{Dropdown-ZLS04O8p.js → Dropdown-D1Jl35dw.js} +1 -1
  103. package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-6CqoDF_P.js} +1 -1
  104. package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-CJa27G_Q.js} +1 -1
  105. package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-CJX35rZL.js} +1 -1
  106. package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CMW0xz0P.js} +1 -1
  107. package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-Cq4daBFb.js} +1 -1
  108. package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DoELa83U.js} +1 -1
  109. package/web/dist/assets/{ModelConfigModal-DDZccDYt.js → ModelConfigModal-Bp7tfKYh.js} +1 -1
  110. package/web/dist/assets/{PiSetupModal-DHbqfx8T.js → PiSetupModal-DD8srwBJ.js} +1 -1
  111. package/web/dist/assets/{ProviderOAuthControls-C-MK36Dk.js → ProviderOAuthControls-C6tfXb88.js} +1 -1
  112. package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-CghgsyBN.js} +1 -1
  113. package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-D8-8aqwC.js} +1 -1
  114. package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-BbBe2rYo.js} +1 -1
  115. package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-qETiVPKj.js} +1 -1
  116. package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-Da-Xs4Wk.js} +1 -1
  117. package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DnS4tFQO.js} +1 -1
  118. package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-CGyGkKYl.js} +1 -1
  119. package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-CpBKjG6x.js} +1 -1
  120. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-7EvUHhKQ.js} +1 -1
  121. package/web/dist/assets/{fi-DaSO0Q-m.js → fi-NyN-ZrgD.js} +2 -2
  122. package/web/dist/assets/{index-D6u8xH0o.js → index-DK3F5ZJo.js} +50 -50
  123. package/web/dist/assets/{index-BPvpea8t.js → index-DQMii2he.js} +50 -50
  124. package/web/dist/assets/index-vwBnwzkr.css +1 -0
  125. package/web/dist/assets/{plugin-host-BRBg6zmQ.js → plugin-host-BCnX3P8U.js} +1 -1
  126. package/web/dist/assets/{theme-DDl-Oy1b.js → theme-D2DMH6tH.js} +1 -1
  127. package/web/dist/index.html +35 -35
  128. package/web/dist/sw.js +179 -179
  129. package/web/public/sw.js +179 -179
  130. package/web/dist/assets/index-DDZMv6LO.css +0 -1
@@ -1,235 +1,235 @@
1
- #!/usr/bin/env node
2
- /**
3
- * pi-web-ui DSH runtime launcher (DshEngine的运行时子进程).
4
- *
5
- * 组合 = 全局/本地 dsh 运行时树里的 dsh-base bundle patch + 本文件同目录的
6
- * override patch(挂 stdio JSON-RPC 服务插件 + pin 会话持久化/人设/沙箱)。
7
- * 与官方 dsh CLI 的 profile 机制无关 —— 直接以 boot() 组合静态入口,绕开
8
- * $DSH_HOME/profiles 初始化。
9
- *
10
- * 运行时树解析顺序(实现见 runtime-root.mjs,支持 flat / dsh 嵌套两种布局):
11
- * 1. $PI_WEB_DSH_RUNTIME — 显式指定 node_modules 根(含 @deepseek-ai/dsh-base)
12
- * 2. 本包 node_modules — 若 pi-web-ui 完整安装了 dsh 依赖树
13
- * 3. execPath 邻近 node_modules — fnm / 独立 node 的稳定布局
14
- * 4. `npm root -g` — 全局 dsh 安装(`npm i -g @deepseek-ai/dsh`)
15
- *
16
- * JSON-RPC 服务插件(dsh-sdk-jsonrpc-server)按项目依赖解析:override patch
17
- * 里的 name 由 $PI_WEB_DSH_JSONRPC_ENTRY 用 !!js 求值成绝对路径(指向项目
18
- * node_modules),其 peer 依赖从项目树自洽解析 —— cordis loader 的裸包解析
19
- * 只有单一 base,所以混树只能走绝对路径挂载。
20
- *
21
- * 协议:newline-delimited JSON-RPC 2.0 于 stdio(stdout 只承载协议帧)。
22
- */
23
- import { dirname, join, resolve } from "node:path";
24
- import { readdirSync } from "node:fs";
25
- import { fileURLToPath, pathToFileURL } from "node:url";
26
- import { resolveRuntimeBaseWithDetails, getExpectedDshVersion, getDshFamily } from "./runtime-root.mjs";
27
-
28
- const HERE = dirname(fileURLToPath(import.meta.url));
29
- const BIN_NAME = "pi-web-ui-dsh";
30
-
31
- const expectedVersion = getExpectedDshVersion();
32
- const expectedFamily = getDshFamily(expectedVersion);
33
-
34
- const { base: runtimeBase, scannedPaths, compatibility } = await resolveRuntimeBaseWithDetails();
35
- if (!runtimeBase) {
36
- const pathList = scannedPaths
37
- .slice(0, 15)
38
- .map((s) => ` - ${s.path} (${s.exists ? s.reason || "已存在但非有效运行时树" : "不存在"})`)
39
- .join("\n");
40
- const more = scannedPaths.length > 15 ? `\n ... 另有 ${scannedPaths.length - 15} 处候选` : "";
41
- process.stderr.write(
42
- `[${BIN_NAME}] 找不到 DSH 运行时树(含 @deepseek-ai/dsh-base 的 node_modules)。\n` +
43
- `请先执行 npm i -g @deepseek-ai/dsh@${expectedVersion}(或设置 PI_WEB_DSH_RUNTIME 指向其 node_modules 目录)。\n\n` +
44
- `已探测的候选路径:\n${pathList}${more}\n\n` +
45
- `详见文档 docs/dsh-engine.md。\n`,
46
- );
47
- process.exit(1);
48
- }
49
-
50
- process.env.PI_WEB_DSH_RUNTIME_BASE = runtimeBase;
51
-
52
- // 检查版本族兼容性(默认宽松尝试运行;若需严格匹配可设置 PI_WEB_DSH_STRICT_VERSION=1)
53
- if (!compatibility?.compatible) {
54
- const strictVer = process.env.PI_WEB_DSH_STRICT_VERSION === "1" || process.env.PI_WEB_DSH_STRICT_VERSION === "true";
55
- const verMsg =
56
- `[${BIN_NAME}] 注意:检测到 DSH 运行时版本(${compatibility?.runtimeVersion ?? "未知"})与期望版本(${expectedVersion},版本族 ${expectedFamily})不同。\n` +
57
- ` - 运行时树位置:${runtimeBase}\n` +
58
- ` - 默认以可用运行时树为准并尝试向前兼容启动。如需强制版本一致,可设置 PI_WEB_DSH_STRICT_VERSION=1。\n`;
59
-
60
- if (strictVer) {
61
- process.stderr.write(
62
- `[${BIN_NAME}] DSH 运行时版本族不匹配(已开启 PI_WEB_DSH_STRICT_VERSION 严格模式):\n` +
63
- ` - 检测到运行时版本:${compatibility?.runtimeVersion ?? "未知"}(位于 ${runtimeBase})\n` +
64
- ` - pi-web-ui 期望版本族:${expectedFamily}(当前依赖 @deepseek-ai/dsh@${expectedVersion})\n\n` +
65
- `推荐解决方案:\n` +
66
- ` 1. 全局安装匹配版本的运行时:\n` +
67
- ` npm i -g @deepseek-ai/dsh@${expectedVersion}\n` +
68
- ` 2. 或通过独立前缀安装并配置环境变量(推荐,不影响全局 CLI):\n` +
69
- ` npm i -g @deepseek-ai/dsh@${expectedVersion} --prefix ~/.pi-web/dsh-runtime-${expectedFamily}\n` +
70
- ` 并在启动 pi-web-ui 时设置环境变量:\n` +
71
- ` PI_WEB_DSH_RUNTIME=~/.pi-web/dsh-runtime-${expectedFamily}/lib/node_modules\n\n` +
72
- `详见文档 docs/dsh-engine.md。\n`,
73
- );
74
- process.exit(1);
75
- } else {
76
- process.stderr.write(verMsg);
77
- }
78
- }
79
-
80
- const runConfig = process.env.DSH_CORDIS_CONFIG ?? join(HERE, "cordis.yml");
81
- const baseBundlePatch = join(runtimeBase, "@deepseek-ai", "dsh-base", "cordis.patch.yml");
82
- const overridePatch = join(HERE, "override.patch.yml");
83
-
84
- // 用户 patch 层:<dataDir>/dsh-patches/*.yml(按文件名序,在 override 之后)。
85
- // 引擎(DshClientSession)负责在重启运行时前创建目录;launcher 只负责加载。
86
- const userPatchDir = process.env.PI_WEB_DSH_DATA_DIR
87
- ? join(process.env.PI_WEB_DSH_DATA_DIR, "dsh-patches")
88
- : (process.env.PI_WEB_DSH_PATCH_DIR ?? null);
89
- const userPatchFiles = [];
90
- if (userPatchDir) {
91
- try {
92
- for (const name of readdirSync(userPatchDir)) {
93
- if (/^[^.]/u.test(name) && /\.ya?ml$/iu.test(name)) {
94
- userPatchFiles.push(join(userPatchDir, name));
95
- }
96
- }
97
- } catch {
98
- // 目录不存在/不可读 = 无用户 patch,静默跳过。
99
- }
100
- }
101
- userPatchFiles.sort((a, b) => a.localeCompare(b));
102
-
103
- // preset-plane patch 路径(服务端生成的 agent-plane 下沉层,见
104
- // server/dsh/preset-clones.ts)。实际加载在 boot import 之后;缺失/不可读 =
105
- // 回落 legacy 单组合(roster 不挂,会话走 host 直连),静默跳过。
106
- const presetPlanePatch = process.env.PI_WEB_DSH_PRESET_PATCH ?? null;
107
-
108
- // ---------------------------------------------------------------------------
109
- // boot
110
- // ---------------------------------------------------------------------------
111
-
112
- const { boot, installFailLoud, loadOverlayPatches } = await import(
113
- pathToFileURL(join(runtimeBase, "@deepseek-ai", "dsh-app-boot", "lib", "index.js")).href
114
- );
115
-
116
- // cordis loader 只对 entry 的 config 做 !!js 插值,name 字段不支持。
117
- // sdk-jsonrpc 走本地扩展插件 goal-rpc.mjs(官方 server 类 + goal RPC 方法);
118
- // 官方入口(base 类)通过 env PI_WEB_DSH_JSONRPC_ENTRY 传给 wrapper。
119
- const jsonrpcWrapper = join(HERE, "goal-rpc.mjs");
120
- const _jsonrpcEntry = process.env.PI_WEB_DSH_JSONRPC_ENTRY
121
- ? resolve(process.env.PI_WEB_DSH_JSONRPC_ENTRY)
122
- : join(
123
- resolve(HERE, "..", "..", "..", ".."),
124
- "node_modules",
125
- "@deepseek-ai",
126
- "dsh-sdk-jsonrpc-server",
127
- "lib",
128
- "index.js",
129
- );
130
-
131
- const overrideList = loadOverlayPatches(BIN_NAME, overridePatch);
132
- // cordis loader 只对 entry 的 config 做 !!js 插值,name 字段不支持——
133
- // 插件绝对路径在这里用 JS 写回(sdk-jsonrpc → 本地 goal-rpc wrapper;
134
- // 用户 patch 若用 id 覆盖 sdk-jsonrpc 或 insert 同名 entry 也拿到 wrapper)。
135
- const fixJsonrpcName = (patch) => {
136
- if (patch.id === "sdk-jsonrpc") {
137
- patch.name = jsonrpcWrapper;
138
- }
139
- for (const entry of patch.insert ?? []) {
140
- if (entry.id === "sdk-jsonrpc") entry.name = jsonrpcWrapper;
141
- }
142
- };
143
- for (const patch of overrideList) fixJsonrpcName(patch);
144
- const userPatchLists = userPatchFiles.map((file) => {
145
- try {
146
- return loadOverlayPatches(BIN_NAME, file);
147
- } catch (err) {
148
- process.stderr.write(`[${BIN_NAME}] 跳过用户 patch ${file}: ${err?.message ?? String(err)}\n`);
149
- return [];
150
- }
151
- });
152
- for (const list of userPatchLists) for (const patch of list) fixJsonrpcName(patch);
153
- // preset-plane patch(服务端生成;override 之后、用户 patch 之前)。
154
- let presetPlaneLists = [];
155
- if (presetPlanePatch) {
156
- try {
157
- presetPlaneLists = loadOverlayPatches(BIN_NAME, presetPlanePatch);
158
- } catch (err) {
159
- process.stderr.write(`[${BIN_NAME}] 跳过 preset-plane patch ${presetPlanePatch}: ${err?.message ?? String(err)}\n`);
160
- presetPlaneLists = [];
161
- }
162
- }
163
- for (const patch of presetPlaneLists) fixJsonrpcName(patch);
164
- // patches 参数必须是扁平列表(boot → mountRootInclude → Include.applyPatches →
165
- // applyEntryPatches 逐个消费;数组嵌套会被当无 id 的 patch 跳过)。
166
- const patches = [
167
- ...loadOverlayPatches(BIN_NAME, baseBundlePatch),
168
- ...overrideList,
169
- ...presetPlaneLists,
170
- // 用户 patch:同样按文件展开为扁平 patch entry 列表(一个文件可含多 entry)。
171
- ...userPatchLists.flat(),
172
- ];
173
-
174
- let ctx;
175
- try {
176
- ctx = await boot(
177
- BIN_NAME,
178
- runConfig,
179
- patches,
180
- undefined,
181
- // 裸包名(dsh-base 组合行)锚定到运行时树;jsonrpc 行走绝对路径。
182
- pathToFileURL(runtimeBase + "/").href,
183
- );
184
- } catch (err) {
185
- const seen = new Set();
186
- let isTypertFailure = false;
187
- const walk = (e, depth) => {
188
- if (!e || seen.has(e)) return;
189
- seen.add(e);
190
- const msg = e?.message ?? String(e);
191
- if (
192
- msg.includes("typert contributor") ||
193
- msg.includes("codec has no create() factory") ||
194
- msg.includes("typert-loader")
195
- ) {
196
- isTypertFailure = true;
197
- }
198
- const indent = " " + " ".repeat(Math.min(depth, 6));
199
- process.stderr.write(`${indent}${msg}\n`);
200
- const kids = e?.aggregateErrors ?? e?.errors ?? (e?.cause ? [e.cause] : []);
201
- for (const k of kids) walk(k, depth + 1);
202
- };
203
- process.stderr.write(`[${BIN_NAME}] boot 失败: ${err?.message ?? String(err)}\n runtime base: ${runtimeBase}\n`);
204
- walk(err, 0);
205
- if (isTypertFailure || !compatibility?.compatible) {
206
- process.stderr.write(
207
- `\n[${BIN_NAME}] 诊断:检测到启动失败。当前运行时版本为 ${compatibility?.runtimeVersion ?? "未知"}(期望版本族 ${expectedFamily})。\n` +
208
- `若因跨版本破坏性变更引起,请执行 npm i -g @deepseek-ai/dsh@${expectedVersion} 重新安装匹配版本的运行时。\n\n`,
209
- );
210
- }
211
- process.exit(1);
212
- }
213
-
214
- let releasing = false;
215
- const release = () => {
216
- if (releasing) return;
217
- releasing = true;
218
- void (async () => {
219
- try {
220
- await ctx.fiber.dispose();
221
- } catch (err) {
222
- console.error(`[${BIN_NAME}] teardown 错误: ${err?.message ?? String(err)}`);
223
- }
224
- process.exit(0);
225
- })();
226
- return true;
227
- };
228
- installFailLoud(BIN_NAME, process, release);
229
-
230
- // stdin EOF = 客户端消失 → 有序释放后退出。
231
- process.stdin.resume();
232
- process.stdin.on("end", release);
233
- process.stdin.on("close", release);
234
- process.on("SIGTERM", release);
235
- process.on("SIGINT", () => process.exit(130));
1
+ #!/usr/bin/env node
2
+ /**
3
+ * pi-web-ui DSH runtime launcher (DshEngine的运行时子进程).
4
+ *
5
+ * 组合 = 全局/本地 dsh 运行时树里的 dsh-base bundle patch + 本文件同目录的
6
+ * override patch(挂 stdio JSON-RPC 服务插件 + pin 会话持久化/人设/沙箱)。
7
+ * 与官方 dsh CLI 的 profile 机制无关 —— 直接以 boot() 组合静态入口,绕开
8
+ * $DSH_HOME/profiles 初始化。
9
+ *
10
+ * 运行时树解析顺序(实现见 runtime-root.mjs,支持 flat / dsh 嵌套两种布局):
11
+ * 1. $PI_WEB_DSH_RUNTIME — 显式指定 node_modules 根(含 @deepseek-ai/dsh-base)
12
+ * 2. 本包 node_modules — 若 pi-web-ui 完整安装了 dsh 依赖树
13
+ * 3. execPath 邻近 node_modules — fnm / 独立 node 的稳定布局
14
+ * 4. `npm root -g` — 全局 dsh 安装(`npm i -g @deepseek-ai/dsh`)
15
+ *
16
+ * JSON-RPC 服务插件(dsh-sdk-jsonrpc-server)按项目依赖解析:override patch
17
+ * 里的 name 由 $PI_WEB_DSH_JSONRPC_ENTRY 用 !!js 求值成绝对路径(指向项目
18
+ * node_modules),其 peer 依赖从项目树自洽解析 —— cordis loader 的裸包解析
19
+ * 只有单一 base,所以混树只能走绝对路径挂载。
20
+ *
21
+ * 协议:newline-delimited JSON-RPC 2.0 于 stdio(stdout 只承载协议帧)。
22
+ */
23
+ import { dirname, join, resolve } from "node:path";
24
+ import { readdirSync } from "node:fs";
25
+ import { fileURLToPath, pathToFileURL } from "node:url";
26
+ import { resolveRuntimeBaseWithDetails, getExpectedDshVersion, getDshFamily } from "./runtime-root.mjs";
27
+
28
+ const HERE = dirname(fileURLToPath(import.meta.url));
29
+ const BIN_NAME = "pi-web-ui-dsh";
30
+
31
+ const expectedVersion = getExpectedDshVersion();
32
+ const expectedFamily = getDshFamily(expectedVersion);
33
+
34
+ const { base: runtimeBase, scannedPaths, compatibility } = await resolveRuntimeBaseWithDetails();
35
+ if (!runtimeBase) {
36
+ const pathList = scannedPaths
37
+ .slice(0, 15)
38
+ .map((s) => ` - ${s.path} (${s.exists ? s.reason || "已存在但非有效运行时树" : "不存在"})`)
39
+ .join("\n");
40
+ const more = scannedPaths.length > 15 ? `\n ... 另有 ${scannedPaths.length - 15} 处候选` : "";
41
+ process.stderr.write(
42
+ `[${BIN_NAME}] 找不到 DSH 运行时树(含 @deepseek-ai/dsh-base 的 node_modules)。\n` +
43
+ `请先执行 npm i -g @deepseek-ai/dsh@${expectedVersion}(或设置 PI_WEB_DSH_RUNTIME 指向其 node_modules 目录)。\n\n` +
44
+ `已探测的候选路径:\n${pathList}${more}\n\n` +
45
+ `详见文档 docs/dsh-engine.md。\n`,
46
+ );
47
+ process.exit(1);
48
+ }
49
+
50
+ process.env.PI_WEB_DSH_RUNTIME_BASE = runtimeBase;
51
+
52
+ // 检查版本族兼容性(默认宽松尝试运行;若需严格匹配可设置 PI_WEB_DSH_STRICT_VERSION=1)
53
+ if (!compatibility?.compatible) {
54
+ const strictVer = process.env.PI_WEB_DSH_STRICT_VERSION === "1" || process.env.PI_WEB_DSH_STRICT_VERSION === "true";
55
+ const verMsg =
56
+ `[${BIN_NAME}] 注意:检测到 DSH 运行时版本(${compatibility?.runtimeVersion ?? "未知"})与期望版本(${expectedVersion},版本族 ${expectedFamily})不同。\n` +
57
+ ` - 运行时树位置:${runtimeBase}\n` +
58
+ ` - 默认以可用运行时树为准并尝试向前兼容启动。如需强制版本一致,可设置 PI_WEB_DSH_STRICT_VERSION=1。\n`;
59
+
60
+ if (strictVer) {
61
+ process.stderr.write(
62
+ `[${BIN_NAME}] DSH 运行时版本族不匹配(已开启 PI_WEB_DSH_STRICT_VERSION 严格模式):\n` +
63
+ ` - 检测到运行时版本:${compatibility?.runtimeVersion ?? "未知"}(位于 ${runtimeBase})\n` +
64
+ ` - pi-web-ui 期望版本族:${expectedFamily}(当前依赖 @deepseek-ai/dsh@${expectedVersion})\n\n` +
65
+ `推荐解决方案:\n` +
66
+ ` 1. 全局安装匹配版本的运行时:\n` +
67
+ ` npm i -g @deepseek-ai/dsh@${expectedVersion}\n` +
68
+ ` 2. 或通过独立前缀安装并配置环境变量(推荐,不影响全局 CLI):\n` +
69
+ ` npm i -g @deepseek-ai/dsh@${expectedVersion} --prefix ~/.pi-web/dsh-runtime-${expectedFamily}\n` +
70
+ ` 并在启动 pi-web-ui 时设置环境变量:\n` +
71
+ ` PI_WEB_DSH_RUNTIME=~/.pi-web/dsh-runtime-${expectedFamily}/lib/node_modules\n\n` +
72
+ `详见文档 docs/dsh-engine.md。\n`,
73
+ );
74
+ process.exit(1);
75
+ } else {
76
+ process.stderr.write(verMsg);
77
+ }
78
+ }
79
+
80
+ const runConfig = process.env.DSH_CORDIS_CONFIG ?? join(HERE, "cordis.yml");
81
+ const baseBundlePatch = join(runtimeBase, "@deepseek-ai", "dsh-base", "cordis.patch.yml");
82
+ const overridePatch = join(HERE, "override.patch.yml");
83
+
84
+ // 用户 patch 层:<dataDir>/dsh-patches/*.yml(按文件名序,在 override 之后)。
85
+ // 引擎(DshClientSession)负责在重启运行时前创建目录;launcher 只负责加载。
86
+ const userPatchDir = process.env.PI_WEB_DSH_DATA_DIR
87
+ ? join(process.env.PI_WEB_DSH_DATA_DIR, "dsh-patches")
88
+ : (process.env.PI_WEB_DSH_PATCH_DIR ?? null);
89
+ const userPatchFiles = [];
90
+ if (userPatchDir) {
91
+ try {
92
+ for (const name of readdirSync(userPatchDir)) {
93
+ if (/^[^.]/u.test(name) && /\.ya?ml$/iu.test(name)) {
94
+ userPatchFiles.push(join(userPatchDir, name));
95
+ }
96
+ }
97
+ } catch {
98
+ // 目录不存在/不可读 = 无用户 patch,静默跳过。
99
+ }
100
+ }
101
+ userPatchFiles.sort((a, b) => a.localeCompare(b));
102
+
103
+ // preset-plane patch 路径(服务端生成的 agent-plane 下沉层,见
104
+ // server/dsh/preset-clones.ts)。实际加载在 boot import 之后;缺失/不可读 =
105
+ // 回落 legacy 单组合(roster 不挂,会话走 host 直连),静默跳过。
106
+ const presetPlanePatch = process.env.PI_WEB_DSH_PRESET_PATCH ?? null;
107
+
108
+ // ---------------------------------------------------------------------------
109
+ // boot
110
+ // ---------------------------------------------------------------------------
111
+
112
+ const { boot, installFailLoud, loadOverlayPatches } = await import(
113
+ pathToFileURL(join(runtimeBase, "@deepseek-ai", "dsh-app-boot", "lib", "index.js")).href
114
+ );
115
+
116
+ // cordis loader 只对 entry 的 config 做 !!js 插值,name 字段不支持。
117
+ // sdk-jsonrpc 走本地扩展插件 goal-rpc.mjs(官方 server 类 + goal RPC 方法);
118
+ // 官方入口(base 类)通过 env PI_WEB_DSH_JSONRPC_ENTRY 传给 wrapper。
119
+ const jsonrpcWrapper = join(HERE, "goal-rpc.mjs");
120
+ const _jsonrpcEntry = process.env.PI_WEB_DSH_JSONRPC_ENTRY
121
+ ? resolve(process.env.PI_WEB_DSH_JSONRPC_ENTRY)
122
+ : join(
123
+ resolve(HERE, "..", "..", "..", ".."),
124
+ "node_modules",
125
+ "@deepseek-ai",
126
+ "dsh-sdk-jsonrpc-server",
127
+ "lib",
128
+ "index.js",
129
+ );
130
+
131
+ const overrideList = loadOverlayPatches(BIN_NAME, overridePatch);
132
+ // cordis loader 只对 entry 的 config 做 !!js 插值,name 字段不支持——
133
+ // 插件绝对路径在这里用 JS 写回(sdk-jsonrpc → 本地 goal-rpc wrapper;
134
+ // 用户 patch 若用 id 覆盖 sdk-jsonrpc 或 insert 同名 entry 也拿到 wrapper)。
135
+ const fixJsonrpcName = (patch) => {
136
+ if (patch.id === "sdk-jsonrpc") {
137
+ patch.name = jsonrpcWrapper;
138
+ }
139
+ for (const entry of patch.insert ?? []) {
140
+ if (entry.id === "sdk-jsonrpc") entry.name = jsonrpcWrapper;
141
+ }
142
+ };
143
+ for (const patch of overrideList) fixJsonrpcName(patch);
144
+ const userPatchLists = userPatchFiles.map((file) => {
145
+ try {
146
+ return loadOverlayPatches(BIN_NAME, file);
147
+ } catch (err) {
148
+ process.stderr.write(`[${BIN_NAME}] 跳过用户 patch ${file}: ${err?.message ?? String(err)}\n`);
149
+ return [];
150
+ }
151
+ });
152
+ for (const list of userPatchLists) for (const patch of list) fixJsonrpcName(patch);
153
+ // preset-plane patch(服务端生成;override 之后、用户 patch 之前)。
154
+ let presetPlaneLists = [];
155
+ if (presetPlanePatch) {
156
+ try {
157
+ presetPlaneLists = loadOverlayPatches(BIN_NAME, presetPlanePatch);
158
+ } catch (err) {
159
+ process.stderr.write(`[${BIN_NAME}] 跳过 preset-plane patch ${presetPlanePatch}: ${err?.message ?? String(err)}\n`);
160
+ presetPlaneLists = [];
161
+ }
162
+ }
163
+ for (const patch of presetPlaneLists) fixJsonrpcName(patch);
164
+ // patches 参数必须是扁平列表(boot → mountRootInclude → Include.applyPatches →
165
+ // applyEntryPatches 逐个消费;数组嵌套会被当无 id 的 patch 跳过)。
166
+ const patches = [
167
+ ...loadOverlayPatches(BIN_NAME, baseBundlePatch),
168
+ ...overrideList,
169
+ ...presetPlaneLists,
170
+ // 用户 patch:同样按文件展开为扁平 patch entry 列表(一个文件可含多 entry)。
171
+ ...userPatchLists.flat(),
172
+ ];
173
+
174
+ let ctx;
175
+ try {
176
+ ctx = await boot(
177
+ BIN_NAME,
178
+ runConfig,
179
+ patches,
180
+ undefined,
181
+ // 裸包名(dsh-base 组合行)锚定到运行时树;jsonrpc 行走绝对路径。
182
+ pathToFileURL(runtimeBase + "/").href,
183
+ );
184
+ } catch (err) {
185
+ const seen = new Set();
186
+ let isTypertFailure = false;
187
+ const walk = (e, depth) => {
188
+ if (!e || seen.has(e)) return;
189
+ seen.add(e);
190
+ const msg = e?.message ?? String(e);
191
+ if (
192
+ msg.includes("typert contributor") ||
193
+ msg.includes("codec has no create() factory") ||
194
+ msg.includes("typert-loader")
195
+ ) {
196
+ isTypertFailure = true;
197
+ }
198
+ const indent = " " + " ".repeat(Math.min(depth, 6));
199
+ process.stderr.write(`${indent}${msg}\n`);
200
+ const kids = e?.aggregateErrors ?? e?.errors ?? (e?.cause ? [e.cause] : []);
201
+ for (const k of kids) walk(k, depth + 1);
202
+ };
203
+ process.stderr.write(`[${BIN_NAME}] boot 失败: ${err?.message ?? String(err)}\n runtime base: ${runtimeBase}\n`);
204
+ walk(err, 0);
205
+ if (isTypertFailure || !compatibility?.compatible) {
206
+ process.stderr.write(
207
+ `\n[${BIN_NAME}] 诊断:检测到启动失败。当前运行时版本为 ${compatibility?.runtimeVersion ?? "未知"}(期望版本族 ${expectedFamily})。\n` +
208
+ `若因跨版本破坏性变更引起,请执行 npm i -g @deepseek-ai/dsh@${expectedVersion} 重新安装匹配版本的运行时。\n\n`,
209
+ );
210
+ }
211
+ process.exit(1);
212
+ }
213
+
214
+ let releasing = false;
215
+ const release = () => {
216
+ if (releasing) return;
217
+ releasing = true;
218
+ void (async () => {
219
+ try {
220
+ await ctx.fiber.dispose();
221
+ } catch (err) {
222
+ console.error(`[${BIN_NAME}] teardown 错误: ${err?.message ?? String(err)}`);
223
+ }
224
+ process.exit(0);
225
+ })();
226
+ return true;
227
+ };
228
+ installFailLoud(BIN_NAME, process, release);
229
+
230
+ // stdin EOF = 客户端消失 → 有序释放后退出。
231
+ process.stdin.resume();
232
+ process.stdin.on("end", release);
233
+ process.stdin.on("close", release);
234
+ process.on("SIGTERM", release);
235
+ process.on("SIGINT", () => process.exit(130));
@@ -1,89 +1,89 @@
1
- # pi-web-ui DSH runtime overrides — applies AFTER the dsh-base bundle patch
2
- # (loaded from the runtime tree). Rows that restate a base row use id-targeted
3
- # REPLACE (last write wins per row); new rows come in a plain insert block.
4
- # !!js 表达式由 Cordis Loader 在挂载时求值(boot 暴露 dshHomePath,process.env
5
- # 直读)。
6
-
7
- # 会话持久化根 —— 覆盖 base 的 dshHomePath('sessions'),让 pi-web-ui 指向自己的数据目录。
8
- - id: session-persistence-jsonl
9
- name: "@deepseek-ai/dsh-session-persistence-jsonl"
10
- config:
11
- root: !!js process.env.DSH_SESSION_ROOT ?? dshHomePath('sessions')
12
-
13
- # Agent 默认模型 —— initialize() 每次都带 provider/model,这里只兜底。
14
- - id: agent-default-model
15
- name: "@deepseek-ai/dsh-agent-default-model"
16
- config:
17
- provider: !!js process.env.DSH_DEFAULT_PROVIDER ?? 'deepseek-official'
18
- model: !!js process.env.DSH_DEFAULT_MODEL ?? 'deepseek-v4-flash'
19
-
20
- # 部署人设(默认空;pi-web-ui 设置面板可注入)。
21
- # 键名必须是 personaPrefix(dsh-system-prompt schema;persona: 会被 zod 静默丢弃)。
22
- - id: system-prompt
23
- name: "@deepseek-ai/dsh-system-prompt"
24
- config:
25
- personaPrefix: !!js process.env.DSH_PERSONA ?? ''
26
-
27
- # 沙箱工作区根(workspace-write 权限模式的护栏边界)。
28
- - id: sandbox-policy
29
- name: "@deepseek-ai/dsh-sandbox-policy"
30
- config:
31
- mode: !!js process.env.DSH_PERMISSION_MODE ?? 'workspace-write'
32
- workspaceRoot: !!js process.env.DSH_CWD ?? process.cwd()
33
-
34
- # 无头 JSON-RPC 服务:没有交互用户来应答审批弹窗;工具在 workspace-write
35
- # 沙箱内直接执行,用户的 Stop 按钮就是控制手段。
36
- - id: approval
37
- name: "@deepseek-ai/dsh-user-approval"
38
- config:
39
- policy: "never"
40
-
41
- # 权限预设表 —— 与 approval=never 组合匹配。patch 语义:整行 config 全量替换,
42
- # 必须重述 base 的全部预设并补上 (workspace-write, never) 组合,显式 defaultPreset。
43
- - id: permission
44
- name: "@deepseek-ai/dsh-permission-presets"
45
- config:
46
- presets:
47
- read-only:
48
- sandbox: read-only
49
- approval: ask
50
- workspace-write:
51
- sandbox: workspace-write
52
- approval: ask
53
- workspace-write-never:
54
- sandbox: workspace-write
55
- approval: never
56
- danger-full-access:
57
- sandbox: danger-full-access
58
- approval: never
59
- defaultPreset: workspace-write-never
60
-
61
- # ── 新行(plain insert)─────────────────────────────────────────────────────
62
- - insert:
63
- # pi-web-ui 自定义系统提示词(设置面板):独立 host section,随 standard/ptc/
64
- # cordis 下发;minimal(complete:true)按官方语义压住。文本走环境变量
65
- # PI_WEB_DSH_CUSTOM_PROMPT(Node 侧维护,变化即重启运行时)。
66
- - id: pi-webui-custom-prompt
67
- name: ./custom-prompt.mjs
68
- # PTC mode 的 TypeScript 运行时(preset 的 tool-presentation 行等它;
69
- # 无此行时 ptc 预设能挂但不出 run_code,PTC 名存实亡)。
70
- - id: code-runtime
71
- name: "@deepseek-ai/dsh-code-runtime-worker-thread"
72
- # 子代理模型选择开关(standard/ptc/cordis 的 tool-subagent 行
73
- # modelSelectionSettings: true 要求它在 Host scope;缺失则整组 mount 失败)。
74
- - id: subagent-model-selection-settings
75
- name: "@deepseek-ai/dsh-tool-subagent/model-selection-settings"
76
- # cordis 模式的宿主执行器(tool-cordis 等 dynamicCordisRunner/cordisInspect;
77
- # 缺失则 cordis 预设 mount 失败)。与官方 dsh-web-app 的 cordis-host-runner 同位。
78
- - id: cordis-host-runner
79
- name: "@deepseek-ai/dsh-cordis-host-runner"
80
- # 模型提问工具:ask_user_question → ctx.userQuestions(base 已挂 user-questions
81
- # 服务)→ goal-rpc wrapper 注册的 provider 桥到浏览器对话框。
82
- - id: tool-ask-user
83
- name: "@deepseek-ai/dsh-tool-ask-user"
84
- # Stdio JSON-RPC 服务插件(inject: agents)。name 用 !!js 求值为绝对路径
85
- # (指向项目 node_modules 里的 dsh-sdk-jsonrpc-server),因为 cordis loader
86
- # 的裸包解析只认 bareModuleBaseUrl(运行时树),混树挂载必须走绝对路径;
87
- # 该插件的 peer 依赖从项目树自洽解析。
88
- - id: sdk-jsonrpc
89
- name: !!js process.env.PI_WEB_DSH_JSONRPC_ENTRY
1
+ # pi-web-ui DSH runtime overrides — applies AFTER the dsh-base bundle patch
2
+ # (loaded from the runtime tree). Rows that restate a base row use id-targeted
3
+ # REPLACE (last write wins per row); new rows come in a plain insert block.
4
+ # !!js 表达式由 Cordis Loader 在挂载时求值(boot 暴露 dshHomePath,process.env
5
+ # 直读)。
6
+
7
+ # 会话持久化根 —— 覆盖 base 的 dshHomePath('sessions'),让 pi-web-ui 指向自己的数据目录。
8
+ - id: session-persistence-jsonl
9
+ name: "@deepseek-ai/dsh-session-persistence-jsonl"
10
+ config:
11
+ root: !!js process.env.DSH_SESSION_ROOT ?? dshHomePath('sessions')
12
+
13
+ # Agent 默认模型 —— initialize() 每次都带 provider/model,这里只兜底。
14
+ - id: agent-default-model
15
+ name: "@deepseek-ai/dsh-agent-default-model"
16
+ config:
17
+ provider: !!js process.env.DSH_DEFAULT_PROVIDER ?? 'deepseek-official'
18
+ model: !!js process.env.DSH_DEFAULT_MODEL ?? 'deepseek-v4-flash'
19
+
20
+ # 部署人设(默认空;pi-web-ui 设置面板可注入)。
21
+ # 键名必须是 personaPrefix(dsh-system-prompt schema;persona: 会被 zod 静默丢弃)。
22
+ - id: system-prompt
23
+ name: "@deepseek-ai/dsh-system-prompt"
24
+ config:
25
+ personaPrefix: !!js process.env.DSH_PERSONA ?? ''
26
+
27
+ # 沙箱工作区根(workspace-write 权限模式的护栏边界)。
28
+ - id: sandbox-policy
29
+ name: "@deepseek-ai/dsh-sandbox-policy"
30
+ config:
31
+ mode: !!js process.env.DSH_PERMISSION_MODE ?? 'workspace-write'
32
+ workspaceRoot: !!js process.env.DSH_CWD ?? process.cwd()
33
+
34
+ # 无头 JSON-RPC 服务:没有交互用户来应答审批弹窗;工具在 workspace-write
35
+ # 沙箱内直接执行,用户的 Stop 按钮就是控制手段。
36
+ - id: approval
37
+ name: "@deepseek-ai/dsh-user-approval"
38
+ config:
39
+ policy: "never"
40
+
41
+ # 权限预设表 —— 与 approval=never 组合匹配。patch 语义:整行 config 全量替换,
42
+ # 必须重述 base 的全部预设并补上 (workspace-write, never) 组合,显式 defaultPreset。
43
+ - id: permission
44
+ name: "@deepseek-ai/dsh-permission-presets"
45
+ config:
46
+ presets:
47
+ read-only:
48
+ sandbox: read-only
49
+ approval: ask
50
+ workspace-write:
51
+ sandbox: workspace-write
52
+ approval: ask
53
+ workspace-write-never:
54
+ sandbox: workspace-write
55
+ approval: never
56
+ danger-full-access:
57
+ sandbox: danger-full-access
58
+ approval: never
59
+ defaultPreset: workspace-write-never
60
+
61
+ # ── 新行(plain insert)─────────────────────────────────────────────────────
62
+ - insert:
63
+ # pi-web-ui 自定义系统提示词(设置面板):独立 host section,随 standard/ptc/
64
+ # cordis 下发;minimal(complete:true)按官方语义压住。文本走环境变量
65
+ # PI_WEB_DSH_CUSTOM_PROMPT(Node 侧维护,变化即重启运行时)。
66
+ - id: pi-webui-custom-prompt
67
+ name: ./custom-prompt.mjs
68
+ # PTC mode 的 TypeScript 运行时(preset 的 tool-presentation 行等它;
69
+ # 无此行时 ptc 预设能挂但不出 run_code,PTC 名存实亡)。
70
+ - id: code-runtime
71
+ name: "@deepseek-ai/dsh-code-runtime-worker-thread"
72
+ # 子代理模型选择开关(standard/ptc/cordis 的 tool-subagent 行
73
+ # modelSelectionSettings: true 要求它在 Host scope;缺失则整组 mount 失败)。
74
+ - id: subagent-model-selection-settings
75
+ name: "@deepseek-ai/dsh-tool-subagent/model-selection-settings"
76
+ # cordis 模式的宿主执行器(tool-cordis 等 dynamicCordisRunner/cordisInspect;
77
+ # 缺失则 cordis 预设 mount 失败)。与官方 dsh-web-app 的 cordis-host-runner 同位。
78
+ - id: cordis-host-runner
79
+ name: "@deepseek-ai/dsh-cordis-host-runner"
80
+ # 模型提问工具:ask_user_question → ctx.userQuestions(base 已挂 user-questions
81
+ # 服务)→ goal-rpc wrapper 注册的 provider 桥到浏览器对话框。
82
+ - id: tool-ask-user
83
+ name: "@deepseek-ai/dsh-tool-ask-user"
84
+ # Stdio JSON-RPC 服务插件(inject: agents)。name 用 !!js 求值为绝对路径
85
+ # (指向项目 node_modules 里的 dsh-sdk-jsonrpc-server),因为 cordis loader
86
+ # 的裸包解析只认 bareModuleBaseUrl(运行时树),混树挂载必须走绝对路径;
87
+ # 该插件的 peer 依赖从项目树自洽解析。
88
+ - id: sdk-jsonrpc
89
+ name: !!js process.env.PI_WEB_DSH_JSONRPC_ENTRY