pi-web-ui 0.115.0 → 0.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/bin/pi-web-ui.mjs +21 -1
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +84 -2
- package/dist/server/agent-service.js +107 -26
- package/dist/server/client-state.js +17 -2
- package/dist/server/device-center/bot-execution.js +29 -1
- package/dist/server/device-center/collab-service.js +36 -5
- package/dist/server/device-center/collab-tool.js +90 -5
- package/dist/server/device-center/execution-guides.js +2 -2
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +4 -1
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +58 -3
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +13 -33
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +872 -64
- package/dist/server/device-center/local-hub.js +2 -1
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +74 -1
- package/dist/server/device-center/partition-log.js +293 -0
- package/dist/server/device-center/runtime.js +49 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +163 -64
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/dispatch-domain-handlers.js +14 -3
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +133 -16
- package/dist/server/managed.js +2 -0
- package/dist/server/markers/builtins/services.js +123 -0
- package/dist/server/markers/builtins/todo.js +189 -0
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/orchestrator.js +109 -0
- package/dist/server/plugins.js +64 -7
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/system-prompt-soul.js +41 -0
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/dsh-driver.js +379 -0
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/architecture-plugins.md +946 -0
- package/docs/device-center.md +6 -0
- package/package.json +2 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BDoOpj-F.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0i3O1FT.js} +1 -1
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-B8thymBN.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-zSxyIx1R.js} +3 -3
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-C4LIhshN.js} +1 -1
- package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
- package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BWgU8yPd.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-F7fNimKk.js} +1 -1
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-c6d0TJoh.js} +1 -1
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BmMrrgB9.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-BGSBIKD7.js} +1 -1
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
- package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
- package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-0CYvD72B.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-DDavKvFr.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-BsA-QTvN.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-DzoVQBuG.js} +1 -1
- package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-CUnXlQYX.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-aAKpvKJV.js} +1 -1
- package/web/dist/assets/index-C6DwztqE.css +1 -0
- package/web/dist/assets/index-CuN802Sj.js +93 -0
- package/web/dist/assets/index-EH5Fw9fa.js +93 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-BRWib9DF.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-CfYSMEZg.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D2l_mLNo.js} +1 -1
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -12,38 +12,138 @@
|
|
|
12
12
|
* 3. 严格遵循 package.json 的 exports 条件导出规范解析入口文件;
|
|
13
13
|
* 4. 基于 file:// URL 协议跨环境穿透动态导入 ESM 模块(dynamicImportGlobalPackage)。
|
|
14
14
|
*/
|
|
15
|
-
import { execSync } from "node:child_process";
|
|
16
15
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
17
16
|
import { homedir } from "node:os";
|
|
18
17
|
import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
|
|
19
18
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
20
|
-
|
|
19
|
+
// undefined = 尚未解析;null = 已解析但系统里没有 npm 全局 root
|
|
20
|
+
let cachedNpmRootG;
|
|
21
21
|
let cachedCandidateRoots = null;
|
|
22
22
|
let candidateRootsCachedAt = 0;
|
|
23
23
|
const CANDIDATE_CACHE_TTL_MS = 5000;
|
|
24
24
|
const packageRootCache = new Map();
|
|
25
|
+
/** npm 显式指定的配置文件(npm 自己也认这两个环境变量)。 */
|
|
26
|
+
function npmrcOverrides() {
|
|
27
|
+
const env = process.env;
|
|
28
|
+
const user = env.npm_config_userconfig || env.NPM_CONFIG_USERCONFIG || null;
|
|
29
|
+
const globalConfig = env.npm_config_globalconfig || env.NPM_CONFIG_GLOBALCONFIG || null;
|
|
30
|
+
return { user, global: globalConfig };
|
|
31
|
+
}
|
|
32
|
+
/** prefix 候选(不含 npmrc):环境变量优先,其余来自运行中的 node 二分进制。 */
|
|
33
|
+
function envPrefixes() {
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const p of [process.env.npm_config_prefix, process.env.NPM_CONFIG_PREFIX]) {
|
|
36
|
+
if (p)
|
|
37
|
+
out.push(p);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
25
41
|
/**
|
|
26
|
-
*
|
|
42
|
+
* 默认 prefix:npm 在 POSIX 上取 node 可执行文件的安装前缀,在 Windows 上取 %APPDATA%\npm。
|
|
27
43
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
44
|
+
function defaultPrefixes() {
|
|
45
|
+
const out = [];
|
|
46
|
+
// Windows:npm 的全局 prefix 是 %APPDATA%\npm,跟 node 的安装目录无关,所以排在前面
|
|
47
|
+
if (process.platform === "win32" && process.env.APPDATA)
|
|
48
|
+
out.push(join(process.env.APPDATA, "npm"));
|
|
31
49
|
try {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
encoding: "utf8",
|
|
35
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
36
|
-
shell: process.platform === "win32" ? "cmd.exe" : undefined,
|
|
37
|
-
windowsHide: true,
|
|
38
|
-
}).trim();
|
|
39
|
-
if (out && existsSync(out)) {
|
|
40
|
-
cachedNpmRootG = resolve(out);
|
|
41
|
-
return cachedNpmRootG;
|
|
42
|
-
}
|
|
50
|
+
const nodeDir = dirname(process.execPath);
|
|
51
|
+
out.push(join(nodeDir, ".."), nodeDir);
|
|
43
52
|
}
|
|
44
53
|
catch {
|
|
45
54
|
/* ignore */
|
|
46
55
|
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* npmrc 候选位置:显式覆盖 > 用户级 > 各 prefix 的 etc/npmrc > 平台固定路径(顺序同 npm)。
|
|
60
|
+
*/
|
|
61
|
+
function npmrcLocations(prefixes) {
|
|
62
|
+
const env = process.env;
|
|
63
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
64
|
+
const isWin = process.platform === "win32";
|
|
65
|
+
const { user, global } = npmrcOverrides();
|
|
66
|
+
const locations = [];
|
|
67
|
+
if (user)
|
|
68
|
+
locations.push(user);
|
|
69
|
+
locations.push(join(home, ".npmrc"));
|
|
70
|
+
if (global)
|
|
71
|
+
locations.push(global);
|
|
72
|
+
for (const prefix of prefixes)
|
|
73
|
+
locations.push(join(prefix, "etc", "npmrc"));
|
|
74
|
+
// 包管理器/系统的固定位置(Homebrew 在 Apple Silicon 上走 /opt/homebrew)
|
|
75
|
+
locations.push("/etc/npmrc", "/usr/etc/npmrc", "/usr/local/etc/npmrc", "/opt/homebrew/etc/npmrc");
|
|
76
|
+
if (isWin && env.APPDATA)
|
|
77
|
+
locations.push(join(env.APPDATA, "npm", "etc", "npmrc"));
|
|
78
|
+
if (isWin && env.ProgramFiles)
|
|
79
|
+
locations.push(join(env.ProgramFiles, "nodejs", "etc", "npmrc"));
|
|
80
|
+
return [...new Set(locations.map((loc) => resolve(loc)))];
|
|
81
|
+
}
|
|
82
|
+
/** 从给定位置读取 npmrc 里的 `prefix=`(纯解析,不执行 npm 本体)。 */
|
|
83
|
+
function readNpmrcPrefixes(locations) {
|
|
84
|
+
const home = process.env.HOME || process.env.USERPROFILE || homedir();
|
|
85
|
+
const prefixes = [];
|
|
86
|
+
for (const loc of locations) {
|
|
87
|
+
try {
|
|
88
|
+
if (!existsSync(loc))
|
|
89
|
+
continue;
|
|
90
|
+
for (const line of readFileSync(loc, "utf8").split(/\r?\n/)) {
|
|
91
|
+
const trimmed = line.trim();
|
|
92
|
+
if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith(";"))
|
|
93
|
+
continue;
|
|
94
|
+
const m = trimmed.match(/^prefix\s*=\s*(.+)$/);
|
|
95
|
+
if (!m)
|
|
96
|
+
continue;
|
|
97
|
+
let value = m[1].trim();
|
|
98
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
99
|
+
value = value.slice(1, -1).trim();
|
|
100
|
+
}
|
|
101
|
+
if (value.startsWith("~"))
|
|
102
|
+
value = join(home, value.slice(1));
|
|
103
|
+
if (value && isAbsolute(value))
|
|
104
|
+
prefixes.push(resolve(value));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
/* 配置不可读就跳过,继续下一个位置 */
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return prefixes;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* npm 全局 prefix 候选,优先级同 npm 自身:环境变量 > npmrc 的 prefix= > 默认安装位置。
|
|
115
|
+
*/
|
|
116
|
+
function npmPrefixCandidates() {
|
|
117
|
+
const env = envPrefixes();
|
|
118
|
+
const defaults = defaultPrefixes();
|
|
119
|
+
const fromNpmrc = readNpmrcPrefixes(npmrcLocations([...env, ...defaults]));
|
|
120
|
+
return [...new Set([...env, ...fromNpmrc, ...defaults].filter(Boolean).map((p) => resolve(p)))];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 安全且带缓存地获取系统 npm 全局 root 目录。
|
|
124
|
+
*
|
|
125
|
+
* 纯计算,不再同步执行 `npm root -g`。此前的实现用 execSync 跑这条 npm 命令,而它在
|
|
126
|
+
* 引擎探测的热路径上(probeAllEngines → probeGlobalPackage → getCandidateNodeModulesRoots,
|
|
127
|
+
* 客户端每次请求都可能触发)。同步 spawn 在主线程上做 fork+exec,一旦子进程卡在 exec 之前,
|
|
128
|
+
* 主线程就会永远阻塞在 spawn 错误管道的 read 上,整个事件循环定格(Termux/libuv 上实测的假死)。
|
|
129
|
+
* prefix 完全可以静态推导,代价只有几次 existsSync。
|
|
130
|
+
*/
|
|
131
|
+
export function getSystemNpmRootG() {
|
|
132
|
+
if (cachedNpmRootG !== undefined)
|
|
133
|
+
return cachedNpmRootG;
|
|
134
|
+
// npm 在 POSIX 上装进 <prefix>/lib/node_modules,在 Windows 上装进 <prefix>/node_modules
|
|
135
|
+
const layouts = process.platform === "win32"
|
|
136
|
+
? ["node_modules", join("lib", "node_modules")]
|
|
137
|
+
: [join("lib", "node_modules"), "node_modules"];
|
|
138
|
+
for (const prefix of npmPrefixCandidates()) {
|
|
139
|
+
for (const layout of layouts) {
|
|
140
|
+
const root = join(prefix, layout);
|
|
141
|
+
if (existsSync(root)) {
|
|
142
|
+
cachedNpmRootG = resolve(root);
|
|
143
|
+
return cachedNpmRootG;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
47
147
|
cachedNpmRootG = null;
|
|
48
148
|
return null;
|
|
49
149
|
}
|
|
@@ -57,8 +157,8 @@ export function getCandidateNodeModulesRoots(options) {
|
|
|
57
157
|
Date.now() - candidateRootsCachedAt < CANDIDATE_CACHE_TTL_MS) {
|
|
58
158
|
return cachedCandidateRoots;
|
|
59
159
|
}
|
|
60
|
-
//
|
|
61
|
-
cachedNpmRootG =
|
|
160
|
+
// 重新发现时也要重新推导 npm 全局 root(prefix 可能被改过)
|
|
161
|
+
cachedNpmRootG = undefined;
|
|
62
162
|
const candidates = new Set();
|
|
63
163
|
// 1. 本包内部与向上的祖先链路 node_modules
|
|
64
164
|
let cur = dirname(fileURLToPath(import.meta.url));
|
package/dist/server/index.js
CHANGED
|
@@ -74,6 +74,8 @@ import { globalLspPool } from "./lsp-tool.js";
|
|
|
74
74
|
import { buildPiWebTokenCookie, decodeCookieToken, isTlsRequest } from "./auth-cookie.js";
|
|
75
75
|
import { isLoopbackAddress, loadServerFileConfig, saveServerFileConfig, tokenWarning } from "./server-config.js";
|
|
76
76
|
import { renderSetupHtml } from "./setup-page.js";
|
|
77
|
+
import { renderUnauthorizedHtml } from "./unauthorized-page.js";
|
|
78
|
+
import { formatStartupBannerLines } from "./startup-banner.js";
|
|
77
79
|
import { getAppVersion, getPkgRoot } from "./pkg-info.js";
|
|
78
80
|
import { handleFileMessage, handleScmMessage, handleBgServerMessage, handlePresetAndDshMessage, handleModelAndProviderMessage, handleTerminalMessage, handleSessionLifecycleMessage, handlePlanAndGoalMessage, handleScheduleMessage, handleSettingsMessage, handleInteractiveResponseMessage, handleRemoteSshMessage, } from "./dispatch-domain-handlers.js";
|
|
79
81
|
import { RemoteSshService, isRemoteWorkspaceUri, serveRemoteWorkspaceFile, setGlobalRemoteSshService, } from "./remote-ssh-service.js";
|
|
@@ -211,6 +213,10 @@ const LOCALE_BASE_URL = process.env.PI_WEB_LOCALE_BASE_URL?.trim() || "https://r
|
|
|
211
213
|
function appVersion() {
|
|
212
214
|
return getAppVersion();
|
|
213
215
|
}
|
|
216
|
+
/** 本次服务进程的运行实例 id(ready 帧的 runId):
|
|
217
|
+
* 重启即变,同一进程内所有连接共享。客户端用它区分「断线重连」与「新实例」,
|
|
218
|
+
* 决定问卷的已答 id 缓存 / 未确认答案能否保留(否则已答问卷会被在途旧快照复活)。 */
|
|
219
|
+
const SERVER_RUN_ID = randomUUID();
|
|
214
220
|
/** On-disk web-build id: the main JS bundle hash from the built index.html.
|
|
215
221
|
* Changes on every rebuild — stale pages compare and reload themselves.
|
|
216
222
|
* Declared near use (below webDist), not here: webDist is a const further
|
|
@@ -520,6 +526,15 @@ app.use((req, res, next) => {
|
|
|
520
526
|
next();
|
|
521
527
|
return;
|
|
522
528
|
}
|
|
529
|
+
const isHtml = Boolean(req.headers.accept?.includes("text/html"));
|
|
530
|
+
if (isHtml) {
|
|
531
|
+
const isLoopback = isLoopbackAddress(req.socket?.remoteAddress);
|
|
532
|
+
res.status(401);
|
|
533
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
534
|
+
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
|
|
535
|
+
res.send(renderUnauthorizedHtml({ isLoopback, isStaleCookie: Boolean(cookie), port: PORT }));
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
523
538
|
res
|
|
524
539
|
.status(401)
|
|
525
540
|
.send(cookie
|
|
@@ -1373,7 +1388,7 @@ heartbeatTimer.unref?.();
|
|
|
1373
1388
|
import { DshAgentService } from "./dsh/dsh-agent-service.js";
|
|
1374
1389
|
import { UniversalAgentService, ClaudeCodeDriver, probeClaudeCode, CodexDriver } from "./universal/index.js";
|
|
1375
1390
|
import { DurableAgentService } from "./durable/index.js";
|
|
1376
|
-
import { probeAllEngines, probeEngine, getCachedEngineStatuses, updateEngineBackground, isEngineUpdating, ENGINE_PACKAGES, } from "./engine-probe.js";
|
|
1391
|
+
import { probeAllEngines, probeEngine, getCachedEngineStatuses, updateEngineBackground, isEngineUpdating, uninstallEngineBackground, isEngineUninstalling, ENGINE_PACKAGES, } from "./engine-probe.js";
|
|
1377
1392
|
let piServiceInstance = null;
|
|
1378
1393
|
let dshServiceInstance = null;
|
|
1379
1394
|
let claudeServiceInstance = null;
|
|
@@ -1834,6 +1849,7 @@ const scheduler = new SchedulerStore(DATA_DIR, {
|
|
|
1834
1849
|
else {
|
|
1835
1850
|
const runHeadless = () => svc.chatFromScheduler({
|
|
1836
1851
|
id: task.id,
|
|
1852
|
+
name: task.name,
|
|
1837
1853
|
cwd: task.cwd,
|
|
1838
1854
|
prompt: task.prompt,
|
|
1839
1855
|
model: task.model,
|
|
@@ -2564,6 +2580,103 @@ wss.on("connection", (ws) => {
|
|
|
2564
2580
|
});
|
|
2565
2581
|
}
|
|
2566
2582
|
};
|
|
2583
|
+
const handleUninstallEngine = async (msg) => {
|
|
2584
|
+
const targetEngine = String(msg.engineId || "").trim();
|
|
2585
|
+
if (targetEngine === "pi") {
|
|
2586
|
+
send({
|
|
2587
|
+
type: "notice",
|
|
2588
|
+
level: "error",
|
|
2589
|
+
text: "Pi 为内置核心引擎,不支持卸载",
|
|
2590
|
+
textEn: "Pi is the built-in core engine and cannot be uninstalled",
|
|
2591
|
+
});
|
|
2592
|
+
return;
|
|
2593
|
+
}
|
|
2594
|
+
const meta = ENGINE_PACKAGES[targetEngine];
|
|
2595
|
+
if (!meta || !meta.packageName) {
|
|
2596
|
+
send({
|
|
2597
|
+
type: "notice",
|
|
2598
|
+
level: "error",
|
|
2599
|
+
text: `不支持或未知的引擎「${targetEngine}」`,
|
|
2600
|
+
textEn: `Unsupported or unknown engine "${targetEngine}"`,
|
|
2601
|
+
});
|
|
2602
|
+
return;
|
|
2603
|
+
}
|
|
2604
|
+
const refusal = managedRefusal("uninstall_engine", MANAGED);
|
|
2605
|
+
if (refusal) {
|
|
2606
|
+
send({ type: "notice", level: "error", text: refusal });
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
if (isEngineUpdating(targetEngine)) {
|
|
2610
|
+
send({
|
|
2611
|
+
type: "notice",
|
|
2612
|
+
level: "warning",
|
|
2613
|
+
text: `引擎「${targetEngine.toUpperCase()}」正在后台更新中,请稍候再试`,
|
|
2614
|
+
textEn: `Engine "${targetEngine.toUpperCase()}" is currently updating, please wait…`,
|
|
2615
|
+
});
|
|
2616
|
+
return;
|
|
2617
|
+
}
|
|
2618
|
+
if (isEngineUninstalling(targetEngine)) {
|
|
2619
|
+
send({
|
|
2620
|
+
type: "notice",
|
|
2621
|
+
level: "warning",
|
|
2622
|
+
text: `引擎「${targetEngine.toUpperCase()}」正在后台卸载中,请稍候…`,
|
|
2623
|
+
textEn: `Engine "${targetEngine.toUpperCase()}" is already uninstalling, please wait…`,
|
|
2624
|
+
});
|
|
2625
|
+
return;
|
|
2626
|
+
}
|
|
2627
|
+
const engineDisplayNames = {
|
|
2628
|
+
pi: { zh: "Pi", en: "Pi" },
|
|
2629
|
+
dsh: { zh: "DSH", en: "DSH" },
|
|
2630
|
+
claude: { zh: "Claude Code", en: "Claude Code" },
|
|
2631
|
+
codex: { zh: "Codex", en: "Codex" },
|
|
2632
|
+
durable: { zh: "Pi Durable", en: "Pi Durable" },
|
|
2633
|
+
};
|
|
2634
|
+
const displayName = engineDisplayNames[targetEngine] ?? {
|
|
2635
|
+
zh: targetEngine.toUpperCase(),
|
|
2636
|
+
en: targetEngine.toUpperCase(),
|
|
2637
|
+
};
|
|
2638
|
+
const broadcastStatuses = (list) => {
|
|
2639
|
+
const payload = JSON.stringify({ type: "engines_status", engines: list });
|
|
2640
|
+
for (const c of wss.clients) {
|
|
2641
|
+
if (c.readyState === WebSocket.OPEN) {
|
|
2642
|
+
try {
|
|
2643
|
+
c.send(payload);
|
|
2644
|
+
}
|
|
2645
|
+
catch {
|
|
2646
|
+
/* ignore */
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
send({
|
|
2652
|
+
type: "notice",
|
|
2653
|
+
level: "info",
|
|
2654
|
+
text: `正在后台卸载 ${displayName.zh} 引擎(npm uninstall -g ${meta.packageName})…`,
|
|
2655
|
+
textEn: `Uninstalling ${displayName.en} engine in background (npm uninstall -g ${meta.packageName})…`,
|
|
2656
|
+
});
|
|
2657
|
+
const uninstallPromise = uninstallEngineBackground(targetEngine);
|
|
2658
|
+
broadcastStatuses(getCachedEngineStatuses());
|
|
2659
|
+
const res = await uninstallPromise;
|
|
2660
|
+
const freshEngines = await probeAllEngines(true);
|
|
2661
|
+
broadcastStatuses(freshEngines);
|
|
2662
|
+
if (res.ok) {
|
|
2663
|
+
send({
|
|
2664
|
+
type: "notice",
|
|
2665
|
+
level: "info",
|
|
2666
|
+
text: `✅ ${displayName.zh} 引擎卸载完成`,
|
|
2667
|
+
textEn: `✅ ${displayName.en} engine uninstalled successfully`,
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
else {
|
|
2671
|
+
const detail = res.error || (res.output ? res.output.slice(-200) : "");
|
|
2672
|
+
send({
|
|
2673
|
+
type: "notice",
|
|
2674
|
+
level: "error",
|
|
2675
|
+
text: `❌ ${displayName.zh} 引擎卸载失败${detail ? `:${detail}` : ""}`,
|
|
2676
|
+
textEn: `❌ Failed to uninstall ${displayName.en} engine${detail ? `: ${detail}` : ""}`,
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2567
2680
|
const dispatch = (msg, wireBytes) => {
|
|
2568
2681
|
if (!clientId) {
|
|
2569
2682
|
if (!pending.push(msg, wireBytes))
|
|
@@ -2579,6 +2692,10 @@ wss.on("connection", (ws) => {
|
|
|
2579
2692
|
void handleUpdateEngine(msg);
|
|
2580
2693
|
return;
|
|
2581
2694
|
}
|
|
2695
|
+
if (msg.type === "uninstall_engine") {
|
|
2696
|
+
void handleUninstallEngine(msg);
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2582
2699
|
if (msg.type === "check_engines") {
|
|
2583
2700
|
void probeAllEngines(msg.force).then((engines) => {
|
|
2584
2701
|
if (!closed)
|
|
@@ -2663,7 +2780,7 @@ wss.on("connection", (ws) => {
|
|
|
2663
2780
|
return;
|
|
2664
2781
|
if (handleTerminalMessage(msg, cs))
|
|
2665
2782
|
return;
|
|
2666
|
-
if (handleSessionLifecycleMessage(msg, cs, send))
|
|
2783
|
+
if (handleSessionLifecycleMessage(msg, cs, send, service, clientId))
|
|
2667
2784
|
return;
|
|
2668
2785
|
if (handlePlanAndGoalMessage(msg, cs))
|
|
2669
2786
|
return;
|
|
@@ -2899,6 +3016,9 @@ wss.on("connection", (ws) => {
|
|
|
2899
3016
|
// which a managed instance never runs.
|
|
2900
3017
|
appVersion: appVersion(),
|
|
2901
3018
|
buildId: buildId(),
|
|
3019
|
+
// 本进程运行实例 id:客户端靠它区分「断线重连」与「换了新服务」,
|
|
3020
|
+
// 决定已答问卷 id / 未确认答案能否跨连接保留(issue: 问卷无限重生)。
|
|
3021
|
+
runId: SERVER_RUN_ID,
|
|
2902
3022
|
managed: MANAGED,
|
|
2903
3023
|
tabs: TABS ? [...TABS] : undefined,
|
|
2904
3024
|
service: SERVICE_INFO ?? undefined,
|
|
@@ -3170,22 +3290,19 @@ if (process.env[RESTART_CHILD_ENV] === "1") {
|
|
|
3170
3290
|
}
|
|
3171
3291
|
}
|
|
3172
3292
|
httpServer.listen(PORT, HOST, () => {
|
|
3173
|
-
console.log("");
|
|
3174
|
-
console.log(" ⚡ pi-web-ui — web chat for the pi coding agent");
|
|
3175
|
-
console.log(` http://localhost:${PORT}`);
|
|
3176
|
-
console.log(` workspace : ${CWD}`);
|
|
3177
|
-
console.log(` session dir : ${SESSION_DIR_ROOT}`);
|
|
3178
|
-
console.log(` pi SDK : v${VERSION}`);
|
|
3179
|
-
// issue #260:全局那份 pi SDK 不是服务在用的那份(自带副本赢在 Node 解析顺序上)。
|
|
3180
|
-
// #321 起默认已反转(resolve-global-sdk 自动跟随更新的那份),这条提示只在
|
|
3181
|
-
// 「进程没跟上」(升级发生在启动后 / 旧构建没注入钩子)或显式 PI_WEB_SDK=bundled
|
|
3182
|
-
// 钉死自带副本时出现。
|
|
3183
3293
|
const sdkNote = sdkOriginNote(sdkCopies(), VERSION);
|
|
3184
|
-
|
|
3185
|
-
|
|
3294
|
+
const bannerLines = formatStartupBannerLines({
|
|
3295
|
+
port: PORT,
|
|
3296
|
+
host: HOST,
|
|
3297
|
+
token: AUTH_TOKEN,
|
|
3298
|
+
cwd: CWD,
|
|
3299
|
+
sessionDir: SESSION_DIR_ROOT,
|
|
3300
|
+
version: VERSION,
|
|
3301
|
+
sdkNote,
|
|
3302
|
+
});
|
|
3303
|
+
for (const line of bannerLines) {
|
|
3304
|
+
console.log(line);
|
|
3186
3305
|
}
|
|
3187
|
-
console.log(` bind : ${HOST}:${PORT}`);
|
|
3188
|
-
console.log(` setup : http://127.0.0.1:${PORT}/setup (仅本机:配 token/监听/白名单)`);
|
|
3189
3306
|
if (autoGeneratedToken) {
|
|
3190
3307
|
console.log("");
|
|
3191
3308
|
console.log(" ╔═══════════════════════════════════════════════════════════════════════════════╗");
|
package/dist/server/managed.js
CHANGED
|
@@ -33,6 +33,8 @@ export const MANAGED_MESSAGES = [
|
|
|
33
33
|
"install_pi_agent",
|
|
34
34
|
/** Updates an agent engine package via background process. */
|
|
35
35
|
"update_engine",
|
|
36
|
+
/** Uninstalls an agent engine package via background process. */
|
|
37
|
+
"uninstall_engine",
|
|
36
38
|
/** Plugin market: fetches and installs a plugin from the network. */
|
|
37
39
|
"plugin_catalog_add",
|
|
38
40
|
/** Plugin install/update/uninstall run as a background job (issue #152). */
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* builtins/services.ts — 后台服务登记(复刻 pi-marker-tools)。
|
|
3
|
+
*/
|
|
4
|
+
export const SVC_NAMESPACE = "svc";
|
|
5
|
+
export function initServiceState() {
|
|
6
|
+
return { services: [], nextId: 1 };
|
|
7
|
+
}
|
|
8
|
+
function parseId(raw) {
|
|
9
|
+
if (raw === undefined)
|
|
10
|
+
return null;
|
|
11
|
+
const n = Number(raw);
|
|
12
|
+
return Number.isInteger(n) && n > 0 ? n : null;
|
|
13
|
+
}
|
|
14
|
+
function toInt(raw) {
|
|
15
|
+
if (raw === undefined || raw === "")
|
|
16
|
+
return undefined;
|
|
17
|
+
const n = Number(raw);
|
|
18
|
+
return Number.isInteger(n) && n >= 0 ? n : undefined;
|
|
19
|
+
}
|
|
20
|
+
function findService(state, id) {
|
|
21
|
+
return state.services.find((s) => s.id === id);
|
|
22
|
+
}
|
|
23
|
+
function lineOf(s) {
|
|
24
|
+
const meta = [s.pid !== undefined ? `pid ${s.pid}` : "", s.port !== undefined ? `:${s.port}` : ""]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(" ");
|
|
27
|
+
return `${s.stopped ? "[x]" : "[ ]"} #${s.id}: ${s.name}${meta ? ` (${meta})` : ""}${s.command ? ` — ${s.command}` : ""}`;
|
|
28
|
+
}
|
|
29
|
+
export function describeServices(state) {
|
|
30
|
+
if (!state || state.services.length === 0)
|
|
31
|
+
return "[svc] (空)";
|
|
32
|
+
return state.services.map(lineOf).join("\n");
|
|
33
|
+
}
|
|
34
|
+
export const servicesMarker = {
|
|
35
|
+
name: "svc",
|
|
36
|
+
guidance: [
|
|
37
|
+
"- 后台服务登记(todo 风格):[[svc:add:名称,pid=,port=,cmd=]] 登记;[[svc:stop:<id>]] 标记停止;[[svc:resume:<id>]] 标记运行;[[svc:remove:<id>]] 删除;[[svc:clear:]] 清空。",
|
|
38
|
+
"- 用 bash 启动后台服务(nohup ... &、pm2 start、docker run -d 等)后,立即写 [[svc:add:...]] 登记,尽量带 pid= 和 port=;服务退出或被关闭后写 [[svc:stop:<id>]] 保持清单准确。",
|
|
39
|
+
],
|
|
40
|
+
async apply(token, _ctx, _state) {
|
|
41
|
+
const state = _state;
|
|
42
|
+
const op = token.op;
|
|
43
|
+
switch (op) {
|
|
44
|
+
case "add": {
|
|
45
|
+
const name = token.args[0]?.trim();
|
|
46
|
+
if (!name)
|
|
47
|
+
return { applied: false, error: "svc:add 需要一个名称参数 [[svc:add:<名称>,pid=,port=,cmd=]]" };
|
|
48
|
+
const svc = {
|
|
49
|
+
id: state.nextId++,
|
|
50
|
+
name,
|
|
51
|
+
command: token.kwargs["cmd"],
|
|
52
|
+
pid: toInt(token.kwargs["pid"]),
|
|
53
|
+
port: toInt(token.kwargs["port"]),
|
|
54
|
+
startedAt: Date.now(),
|
|
55
|
+
stopped: false,
|
|
56
|
+
};
|
|
57
|
+
state.services.push(svc);
|
|
58
|
+
const meta = [svc.pid !== undefined ? `pid ${svc.pid}` : "", svc.port !== undefined ? `:${svc.port}` : ""]
|
|
59
|
+
.filter(Boolean)
|
|
60
|
+
.join(" ");
|
|
61
|
+
return { applied: true, feedback: `Registered #${svc.id}: ${name}${meta ? ` (${meta})` : ""}` };
|
|
62
|
+
}
|
|
63
|
+
case "stop": {
|
|
64
|
+
const id = parseId(token.args[0]);
|
|
65
|
+
if (id === null)
|
|
66
|
+
return { applied: false, error: `svc:stop 的 id 无效: "${token.args[0] ?? ""}"` };
|
|
67
|
+
const svc = findService(state, id);
|
|
68
|
+
if (!svc)
|
|
69
|
+
return { applied: false, error: `svc:stop 服务 #${id} 不存在` };
|
|
70
|
+
svc.stopped = true;
|
|
71
|
+
svc.stoppedAt = Date.now();
|
|
72
|
+
return { applied: true, feedback: `#${id} ${svc.name} marked stopped` };
|
|
73
|
+
}
|
|
74
|
+
case "resume": {
|
|
75
|
+
const id = parseId(token.args[0]);
|
|
76
|
+
if (id === null)
|
|
77
|
+
return { applied: false, error: `svc:resume 的 id 无效: "${token.args[0] ?? ""}"` };
|
|
78
|
+
const svc = findService(state, id);
|
|
79
|
+
if (!svc)
|
|
80
|
+
return { applied: false, error: `svc:resume 服务 #${id} 不存在` };
|
|
81
|
+
svc.stopped = false;
|
|
82
|
+
svc.stoppedAt = undefined;
|
|
83
|
+
return { applied: true, feedback: `#${id} ${svc.name} marked running` };
|
|
84
|
+
}
|
|
85
|
+
case "remove": {
|
|
86
|
+
const id = parseId(token.args[0]);
|
|
87
|
+
if (id === null)
|
|
88
|
+
return { applied: false, error: `svc:remove 的 id 无效: "${token.args[0] ?? ""}"` };
|
|
89
|
+
const before = state.services.length;
|
|
90
|
+
state.services = state.services.filter((s) => s.id !== id);
|
|
91
|
+
if (state.services.length === before)
|
|
92
|
+
return { applied: false, error: `svc:remove 服务 #${id} 不存在` };
|
|
93
|
+
return { applied: true, feedback: `Removed #${id}` };
|
|
94
|
+
}
|
|
95
|
+
case "clear": {
|
|
96
|
+
const n = state.services.length;
|
|
97
|
+
state.services = [];
|
|
98
|
+
state.nextId = 1;
|
|
99
|
+
return { applied: true, feedback: `Cleared ${n} service(s)` };
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
return { applied: false, error: `svc 未知操作: ${op}` };
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
overlay(state) {
|
|
106
|
+
if (!state || state.services.length === 0)
|
|
107
|
+
return undefined;
|
|
108
|
+
const running = state.services.filter((s) => !s.stopped).length;
|
|
109
|
+
const lines = state.services.map((s) => {
|
|
110
|
+
const mark = s.stopped ? "○" : "●";
|
|
111
|
+
let line = ` ${mark} #${s.id} ${s.name}`;
|
|
112
|
+
if (s.port !== undefined)
|
|
113
|
+
line += ` :${s.port}`;
|
|
114
|
+
if (s.pid !== undefined)
|
|
115
|
+
line += ` (pid ${s.pid})`;
|
|
116
|
+
if (s.stopped)
|
|
117
|
+
line += " 已停止";
|
|
118
|
+
return line;
|
|
119
|
+
});
|
|
120
|
+
return { tool: "svc", lines: [`${running}/${state.services.length} running`, ...lines] };
|
|
121
|
+
},
|
|
122
|
+
init: initServiceState,
|
|
123
|
+
};
|