pi-web-ui 0.105.1 → 0.107.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +84 -2
  2. package/README.md +193 -797
  3. package/README.zh-CN.md +186 -625
  4. package/README.zh-TW.md +781 -0
  5. package/bin/frp-manager.mjs +1488 -0
  6. package/bin/pi-web-ui.mjs +27 -0
  7. package/deploy/nginx-subpath.conf +16 -1
  8. package/dist/server/agent-service-daemon.js +34 -0
  9. package/dist/server/agent-service.js +259 -60
  10. package/dist/server/claim-files-tool.js +8 -1
  11. package/dist/server/client-state.js +136 -30
  12. package/dist/server/conversation-read-tool.js +12 -4
  13. package/dist/server/delegate-task.js +9 -1
  14. package/dist/server/dispatch-domain-handlers.js +15 -0
  15. package/dist/server/dsh/dsh-agent-service.js +848 -246
  16. package/dist/server/dsh/dsh-client.js +59 -18
  17. package/dist/server/dsh/dsh-market-service.js +233 -0
  18. package/dist/server/dsh/dsh-serialize.js +11 -3
  19. package/dist/server/dsh/dsh-sessions.js +64 -2
  20. package/dist/server/dsh/preset-clones.js +12 -1
  21. package/dist/server/dsh/runtime/goal-rpc.mjs +183 -45
  22. package/dist/server/durable/durable-agent-service.js +153 -0
  23. package/dist/server/durable/durable-capabilities.js +11 -0
  24. package/dist/server/durable/durable-driver.js +481 -0
  25. package/dist/server/durable/durable-loader.js +38 -0
  26. package/dist/server/durable/durable-models.js +283 -0
  27. package/dist/server/durable/durable-storage.js +42 -0
  28. package/dist/server/durable/durable-tools.js +45 -0
  29. package/dist/server/durable/index.js +8 -0
  30. package/dist/server/engine-capabilities.js +91 -0
  31. package/dist/server/engine-probe.js +391 -0
  32. package/dist/server/global-loader.js +335 -0
  33. package/dist/server/goal-service.js +23 -12
  34. package/dist/server/i18n.js +20 -1
  35. package/dist/server/index.js +286 -71
  36. package/dist/server/locales.js +1 -0
  37. package/dist/server/managed.js +2 -0
  38. package/dist/server/marker-service.js +5 -19
  39. package/dist/server/markers/index.js +1 -3
  40. package/dist/server/mcp-agent-tool.js +10 -7
  41. package/dist/server/mcp-bridge.js +428 -24
  42. package/dist/server/model-admin.js +172 -74
  43. package/dist/server/model-resolver.js +309 -0
  44. package/dist/server/plugin-installer.js +4 -2
  45. package/dist/server/plugins.js +89 -12
  46. package/dist/server/present-files-tool.js +10 -2
  47. package/dist/server/preset-fields.js +14 -0
  48. package/dist/server/preset-share.js +2 -0
  49. package/dist/server/protocol-version.js +1 -1
  50. package/dist/server/schedule-agent-tool.js +2 -1
  51. package/dist/server/scm-commitmsg.js +3 -2
  52. package/dist/server/sdk-origin.js +2 -2
  53. package/dist/server/serialize.js +1 -1
  54. package/dist/server/settings-service.js +10 -2
  55. package/dist/server/skill-discovery.js +161 -0
  56. package/dist/server/skill-tool.js +2 -1
  57. package/dist/server/slash-commands.js +154 -73
  58. package/dist/server/subagent-templates-hant.js +215 -0
  59. package/dist/server/subagent-templates.js +49 -2
  60. package/dist/server/subagents.js +22 -12
  61. package/dist/server/terminals.js +2 -2
  62. package/dist/server/tool-manager.js +6 -19
  63. package/dist/server/universal/driver-base.js +60 -0
  64. package/dist/server/universal/drivers/claude-code.js +463 -0
  65. package/dist/server/universal/drivers/dsh-driver.js +376 -0
  66. package/dist/server/universal/drivers/mock-driver.js +103 -0
  67. package/dist/server/universal/index.js +10 -0
  68. package/dist/server/universal/session-store.js +100 -0
  69. package/dist/server/universal/universal-attachments.js +175 -0
  70. package/dist/server/universal/universal-service.js +166 -0
  71. package/dist/server/universal/universal-session.js +2664 -0
  72. package/dist/server/universal/universal-types.js +4 -0
  73. package/dist/server/update-check.js +24 -9
  74. package/dist/server/worktree-service.js +1 -1
  75. package/dist/server/worktree-tool.js +9 -7
  76. package/package.json +3 -2
  77. package/plugin-sdk/index.d.ts +12 -2
  78. package/plugins/catalog.json +50 -5
  79. package/themes/dark-teal.css +20 -24
  80. package/themes/flow-light.css +1085 -0
  81. package/themes/flow.css +1094 -0
  82. package/themes/md-preview.css +1 -2
  83. package/themes/wallpaper-flow.css +1158 -0
  84. package/themes/wallpaper-obsidian.css +743 -0
  85. package/themes/zhujian-dark.css +0 -7
  86. package/themes/zhujian.css +0 -7
  87. package/themes/zhupi-dark.css +0 -7
  88. package/themes/zhupi.css +0 -7
  89. package/web/dist/assets/{TerminalPanel-Mk4laCAL.js → TerminalPanel-BnViyTlx.js} +2 -2
  90. package/web/dist/assets/index-cCRCYMwT.css +1 -0
  91. package/web/dist/assets/index-fH5vhkAE.js +690 -0
  92. package/web/dist/index.html +2 -2
  93. package/web/dist/sw.js +1 -1
  94. package/web/dist/assets/index-BDLVjBeK.js +0 -690
  95. package/web/dist/assets/index-BQC6lADz.css +0 -1
@@ -0,0 +1,391 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { VERSION } from "@earendil-works/pi-coding-agent";
5
+ import { runtimeBaseCandidates } from "./dsh/preset-clones.js";
6
+ import { killPidTree } from "./process-utils.js";
7
+ import { probeClaudeCode } from "./universal/drivers/claude-code.js";
8
+ import { compareVersions, defaultFetcher, fetchLatest, NPM_DEFAULT_REGISTRY, } from "./update-check.js";
9
+ import { probeGlobalPackage } from "./global-loader.js";
10
+ export const ENGINE_PACKAGES = {
11
+ pi: {
12
+ id: "pi",
13
+ packageName: "@earendil-works/pi-coding-agent",
14
+ installCommand: "npm i -g @earendil-works/pi-coding-agent",
15
+ },
16
+ dsh: {
17
+ id: "dsh",
18
+ packageName: "@deepseek-ai/dsh",
19
+ installCommand: "npm i -g @deepseek-ai/dsh",
20
+ },
21
+ claude: {
22
+ id: "claude",
23
+ packageName: "@anthropic-ai/claude-code",
24
+ installCommand: "npm i -g @anthropic-ai/claude-code",
25
+ },
26
+ durable: {
27
+ id: "durable",
28
+ packageName: "@earendil-works/pi-durable",
29
+ installCommand: "npm i -g @earendil-works/pi-durable",
30
+ },
31
+ };
32
+ /** 探针缓存 TTL:5 秒(短时多次连接或 UI 打开时免除重复频繁执行进程调用) */
33
+ const CACHE_TTL_MS = 5000;
34
+ /** 远端 npm registry 查询缓存:5 分钟 */
35
+ const REGISTRY_CACHE_TTL_MS = 5 * 60 * 1000;
36
+ const registryCache = new Map();
37
+ let lastProbeAt = 0;
38
+ const updatingEngineIds = new Set();
39
+ function applyUpdatingFlag(list) {
40
+ return list.map((s) => ({
41
+ ...s,
42
+ ...(updatingEngineIds.has(s.id) ? { updating: true } : {}),
43
+ }));
44
+ }
45
+ let cachedStatuses = [
46
+ { id: "pi", installed: true, packageName: ENGINE_PACKAGES.pi.packageName, version: VERSION },
47
+ { id: "dsh", installed: false, packageName: ENGINE_PACKAGES.dsh.packageName },
48
+ { id: "claude", installed: false, packageName: ENGINE_PACKAGES.claude.packageName },
49
+ { id: "durable", installed: false, packageName: ENGINE_PACKAGES.durable.packageName },
50
+ ];
51
+ /**
52
+ * 查询全局包在 npm 远端的最新版本号(带 5 分钟缓存)。
53
+ */
54
+ export async function checkPackageLatest(packageName, force = false) {
55
+ const now = Date.now();
56
+ const cached = registryCache.get(packageName);
57
+ if (!force && cached && now - cached.at < REGISTRY_CACHE_TTL_MS) {
58
+ return cached.latest;
59
+ }
60
+ try {
61
+ const res = await fetchLatest(defaultFetcher, packageName, NPM_DEFAULT_REGISTRY, null);
62
+ registryCache.set(packageName, { at: now, latest: res.latest });
63
+ return res.latest;
64
+ }
65
+ catch {
66
+ return cached?.latest ?? null;
67
+ }
68
+ }
69
+ /**
70
+ * 为已安装的引擎注入 npm 远端更新检测结果(latestVersion 与 hasUpdate 标记)。
71
+ */
72
+ export async function enrichWithUpdateInfo(status, force = false) {
73
+ if (!status.installed || !status.packageName || !status.version) {
74
+ return status;
75
+ }
76
+ try {
77
+ const latest = await checkPackageLatest(status.packageName, force);
78
+ if (latest) {
79
+ status.latestVersion = latest;
80
+ status.hasUpdate = compareVersions(latest, status.version) > 0;
81
+ }
82
+ }
83
+ catch {
84
+ /* best effort */
85
+ }
86
+ return status;
87
+ }
88
+ /**
89
+ * 探测 Pi 原生引擎状态(作为内置/捆绑引擎恒存在)。
90
+ */
91
+ export function probePi() {
92
+ return {
93
+ id: "pi",
94
+ installed: true,
95
+ packageName: ENGINE_PACKAGES.pi.packageName,
96
+ version: VERSION,
97
+ };
98
+ }
99
+ /**
100
+ * 快速探测 DSH 引擎全局包/运行时树是否已安装。
101
+ * 1. 优先检查常见全局 node_modules / 候选路径中的 @deepseek-ai/dsh package.json 与 dsh-base;
102
+ * 2. 回退通过命令行探针执行 `dsh --version`。
103
+ */
104
+ export async function probeDsh() {
105
+ const pkgName = ENGINE_PACKAGES.dsh.packageName;
106
+ // 0. 通用全局包探测器(覆盖 fnm / nvm / pnpm / 全局 prefix 等)
107
+ try {
108
+ const globalProbe = probeGlobalPackage(pkgName);
109
+ if (globalProbe.installed) {
110
+ return { id: "dsh", installed: true, packageName: pkgName, version: globalProbe.version };
111
+ }
112
+ }
113
+ catch {
114
+ /* ignore */
115
+ }
116
+ // 1. 路径快速探测(纯 fs 访问,无进程派生开销)
117
+ try {
118
+ for (const root of runtimeBaseCandidates()) {
119
+ if (!root)
120
+ continue;
121
+ // A. 直接在全局或候选 node_modules 中找到 @deepseek-ai/dsh 包目录
122
+ const dshPkgJson = join(root, "@deepseek-ai", "dsh", "package.json");
123
+ if (existsSync(dshPkgJson)) {
124
+ try {
125
+ const pkg = JSON.parse(readFileSync(dshPkgJson, "utf8"));
126
+ return { id: "dsh", installed: true, packageName: pkgName, version: pkg.version };
127
+ }
128
+ catch {
129
+ return { id: "dsh", installed: true, packageName: pkgName };
130
+ }
131
+ }
132
+ // B. 检查平铺运行树(@deepseek-ai/dsh-base)
133
+ const flatBase = join(root, "@deepseek-ai", "dsh-base", "cordis.patch.yml");
134
+ const flatBoot = join(root, "@deepseek-ai", "dsh-app-boot", "lib", "index.js");
135
+ if (existsSync(flatBase) && existsSync(flatBoot)) {
136
+ return { id: "dsh", installed: true, packageName: pkgName };
137
+ }
138
+ // C. 检查嵌套运行树(@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-base)
139
+ const nestedBase = join(root, "@deepseek-ai", "dsh", "node_modules", "@deepseek-ai", "dsh-base", "cordis.patch.yml");
140
+ const nestedBoot = join(root, "@deepseek-ai", "dsh", "node_modules", "@deepseek-ai", "dsh-app-boot", "lib", "index.js");
141
+ if (existsSync(nestedBase) && existsSync(nestedBoot)) {
142
+ return { id: "dsh", installed: true, packageName: pkgName };
143
+ }
144
+ }
145
+ }
146
+ catch {
147
+ /* ignore fs errors */
148
+ }
149
+ // 2. 命令行回退探测(检查 PATH 中是否有可用的 dsh CLI)
150
+ try {
151
+ const cliProbe = await new Promise((resolve) => {
152
+ execFile("dsh", ["--version"], {
153
+ timeout: 3000,
154
+ shell: process.platform === "win32",
155
+ }, (err, stdout) => {
156
+ if (err) {
157
+ resolve({ installed: false });
158
+ }
159
+ else {
160
+ const v = stdout.trim();
161
+ resolve({ installed: true, version: v || undefined });
162
+ }
163
+ });
164
+ });
165
+ if (cliProbe.installed) {
166
+ return {
167
+ id: "dsh",
168
+ installed: true,
169
+ packageName: pkgName,
170
+ version: cliProbe.version,
171
+ };
172
+ }
173
+ }
174
+ catch {
175
+ /* ignore cli error */
176
+ }
177
+ return { id: "dsh", installed: false, packageName: pkgName };
178
+ }
179
+ /**
180
+ * 探测 Claude Code 引擎状态。
181
+ */
182
+ export async function probeClaude() {
183
+ const pkgName = ENGINE_PACKAGES.claude.packageName;
184
+ try {
185
+ const res = await probeClaudeCode();
186
+ return {
187
+ id: "claude",
188
+ installed: res.installed,
189
+ packageName: pkgName,
190
+ version: res.version,
191
+ };
192
+ }
193
+ catch {
194
+ return { id: "claude", installed: false, packageName: pkgName };
195
+ }
196
+ }
197
+ /**
198
+ * 探测 Pi Durable 引擎状态。
199
+ * 检查当前项目或全局环境(npm -g, fnm, nvm 等)下是否安装了 @earendil-works/pi-durable。
200
+ */
201
+ export async function probeDurable(force = false) {
202
+ const pkgName = ENGINE_PACKAGES.durable.packageName;
203
+ try {
204
+ const probe = probeGlobalPackage(pkgName, { refresh: force });
205
+ if (probe.installed) {
206
+ return {
207
+ id: "durable",
208
+ installed: true,
209
+ packageName: pkgName,
210
+ version: probe.version,
211
+ };
212
+ }
213
+ }
214
+ catch {
215
+ /* ignore */
216
+ }
217
+ return { id: "durable", installed: false, packageName: pkgName };
218
+ }
219
+ /**
220
+ * 按引擎 ID 单独探测状态。
221
+ */
222
+ export async function probeEngine(id, force = false) {
223
+ if (id === "pi")
224
+ return probePi();
225
+ if (!force && Date.now() - lastProbeAt < CACHE_TTL_MS) {
226
+ const found = cachedStatuses.find((e) => e.id === id);
227
+ if (found)
228
+ return found;
229
+ }
230
+ let result;
231
+ if (id === "dsh") {
232
+ result = await probeDsh();
233
+ }
234
+ else if (id === "claude") {
235
+ result = await probeClaude();
236
+ }
237
+ else if (id === "durable") {
238
+ result = await probeDurable();
239
+ }
240
+ else {
241
+ result = { id: id, installed: false };
242
+ }
243
+ await enrichWithUpdateInfo(result, force);
244
+ // 更新单项缓存
245
+ const idx = cachedStatuses.findIndex((e) => e.id === id);
246
+ if (idx >= 0)
247
+ cachedStatuses[idx] = result;
248
+ else
249
+ cachedStatuses.push(result);
250
+ return {
251
+ ...result,
252
+ ...(updatingEngineIds.has(id) ? { updating: true } : {}),
253
+ };
254
+ }
255
+ /**
256
+ * 探测全部已知引擎并返回最新状态列表(带 TTL 缓存防抖)。
257
+ */
258
+ export async function probeAllEngines(force = false) {
259
+ if (!force && Date.now() - lastProbeAt < CACHE_TTL_MS && cachedStatuses.length > 0) {
260
+ return applyUpdatingFlag(cachedStatuses);
261
+ }
262
+ const [pi, dsh, claude, durable] = await Promise.all([probePi(), probeDsh(), probeClaude(), probeDurable()]);
263
+ await Promise.all([
264
+ enrichWithUpdateInfo(pi, force),
265
+ enrichWithUpdateInfo(dsh, force),
266
+ enrichWithUpdateInfo(claude, force),
267
+ enrichWithUpdateInfo(durable, force),
268
+ ]);
269
+ cachedStatuses = [pi, dsh, claude, durable];
270
+ lastProbeAt = Date.now();
271
+ return applyUpdatingFlag(cachedStatuses);
272
+ }
273
+ /**
274
+ * 同步获取当前缓存的引擎探测结果(握手帧或即时读取使用)。
275
+ */
276
+ export function getCachedEngineStatuses() {
277
+ return applyUpdatingFlag(cachedStatuses);
278
+ }
279
+ /**
280
+ * 查询指定引擎是否正在执行后台更新子进程。
281
+ */
282
+ export function isEngineUpdating(engineId) {
283
+ return updatingEngineIds.has(engineId);
284
+ }
285
+ /**
286
+ * 在后台子进程中执行引擎全局包更新(npm i -g <pkg>@latest)。
287
+ * 避免在可见终端中通过 PTY 模拟输入导致命令首字母丢失或输入不全的问题。
288
+ */
289
+ export async function updateEngineBackground(engineId, options) {
290
+ const meta = ENGINE_PACKAGES[engineId];
291
+ if (!meta || !meta.packageName) {
292
+ return { ok: false, error: `不支持或未知的引擎「${engineId}」` };
293
+ }
294
+ if (updatingEngineIds.has(engineId)) {
295
+ return { ok: false, error: `引擎「${engineId}」正在后台更新中,请勿重复操作` };
296
+ }
297
+ updatingEngineIds.add(engineId);
298
+ const pkg = meta.packageName;
299
+ const timeoutMs = Math.max(10_000, Number(options?.timeoutMs ?? 300_000));
300
+ const isWin = process.platform === "win32";
301
+ const spawnCmd = isWin ? process.env.ComSpec || "cmd.exe" : "npm";
302
+ const spawnArgs = isWin ? ["/d", "/s", "/c", "npm", "i", "-g", `${pkg}@latest`] : ["i", "-g", `${pkg}@latest`];
303
+ try {
304
+ const child = spawn(spawnCmd, spawnArgs, {
305
+ windowsHide: true,
306
+ detached: !isWin,
307
+ stdio: ["ignore", "pipe", "pipe"],
308
+ env: {
309
+ ...process.env,
310
+ NO_COLOR: "1",
311
+ },
312
+ });
313
+ let out = "";
314
+ const appendOut = (chunk) => {
315
+ out = (out + chunk.toString()).slice(-8000);
316
+ };
317
+ child.stdout?.on("data", appendOut);
318
+ child.stderr?.on("data", appendOut);
319
+ const res = await new Promise((resolve) => {
320
+ let done = false;
321
+ const timer = setTimeout(() => {
322
+ if (done)
323
+ return;
324
+ done = true;
325
+ if (child.pid)
326
+ void killPidTree(child.pid);
327
+ resolve({ ok: false, code: null, error: `更新超时(超过 ${Math.round(timeoutMs / 1000)} 秒)` });
328
+ }, timeoutMs);
329
+ child.on("error", (err) => {
330
+ if (done)
331
+ return;
332
+ done = true;
333
+ clearTimeout(timer);
334
+ resolve({ ok: false, code: null, error: err.message });
335
+ });
336
+ child.on("close", (code) => {
337
+ if (done)
338
+ return;
339
+ done = true;
340
+ clearTimeout(timer);
341
+ resolve({
342
+ ok: code === 0,
343
+ code,
344
+ error: code === 0 ? undefined : `npm 退出码 ${code}`,
345
+ });
346
+ });
347
+ });
348
+ if (res.ok) {
349
+ registryCache.delete(pkg);
350
+ try {
351
+ await probeAllEngines(true);
352
+ }
353
+ catch {
354
+ /* best effort */
355
+ }
356
+ }
357
+ return {
358
+ ok: res.ok,
359
+ error: res.error,
360
+ output: out.trim(),
361
+ };
362
+ }
363
+ catch (err) {
364
+ return {
365
+ ok: false,
366
+ error: err.message,
367
+ };
368
+ }
369
+ finally {
370
+ updatingEngineIds.delete(engineId);
371
+ }
372
+ }
373
+ /**
374
+ * 收集已安装的第三方全局引擎包,供全量更新检查(check_updates_all)纳入统一检查名录。
375
+ */
376
+ export function collectInstalledEngineTargets() {
377
+ const out = [];
378
+ for (const status of cachedStatuses) {
379
+ // pi-core 在 collectTargets 中已有独立专属条目(PI_CORE_PACKAGE),此处收纳其他已安装引擎全局包
380
+ if (status.id !== "pi" && status.installed && status.packageName && status.version) {
381
+ out.push({
382
+ name: status.packageName,
383
+ version: status.version,
384
+ kind: "engine",
385
+ });
386
+ }
387
+ }
388
+ return out;
389
+ }
390
+ // 模块加载时预热后台探测
391
+ void probeAllEngines(true).catch(() => { });