pi-web-ui 0.113.0 → 0.114.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 +69 -1
- package/README.md +117 -252
- package/README.zh-CN.md +145 -223
- package/README.zh-TW.md +145 -223
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +145 -20
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2296 -1121
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +18 -8
- package/dist/server/canvas/canvas-agent-tool.js +65 -15
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +516 -199
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +104 -22
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/control-socket.js +6 -2
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +332 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +829 -0
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +476 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +959 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +83 -27
- package/dist/server/dsh/dsh-agent-service.js +277 -158
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +110 -34
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +236 -232
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +262 -92
- package/dist/server/preset-fields.js +49 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +112 -72
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +160 -67
- package/dist/server/request-context.js +164 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/scheduler-tasks.js +63 -48
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +267 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +47 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +334 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/webui-context.js +6 -6
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/device-center.md +142 -0
- package/docs/device-desktop.md +48 -0
- package/package.json +4 -1
- package/plugin-sdk/index.d.ts +45 -9
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +1 -1
- package/themes/aetheris.css +1 -107
- package/themes/ayu-light.css +5 -29
- package/themes/bases/flow-base.css +0 -6
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +1 -0
- package/themes/bases/zhupi-base.css +1 -0
- package/themes/catppuccin-latte.css +4 -27
- package/themes/catppuccin.css +4 -35
- package/themes/claude-code-dark.css +1 -0
- package/themes/codex.css +4 -28
- package/themes/cyberpunk.css +3 -61
- package/themes/dark-teal.css +0 -1
- package/themes/dazzle.css +3 -73
- package/themes/everforest-light.css +4 -27
- package/themes/geist.css +4 -28
- package/themes/gruvbox-light.css +4 -27
- package/themes/kanagawa-lotus.css +4 -27
- package/themes/md-preview.css +3 -213
- package/themes/mist.css +4 -24
- package/themes/nord.css +4 -35
- package/themes/one-dark.css +4 -37
- package/themes/paper.css +4 -16
- package/themes/rose-pine-dawn.css +4 -28
- package/themes/sakura.css +4 -24
- package/themes/solarized-light.css +4 -27
- package/themes/tokyo-night.css +3 -34
- package/themes/white.css +4 -26
- package/themes/zhujian-dark.css +1 -0
- package/themes/zhupi-dark.css +1 -0
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
- package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
- package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
- package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
- package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
- package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
- package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
- package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
- package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
- package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
- package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
- package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/index-CPgAH5q7.js +83 -0
- package/web/dist/assets/index-Cje8iugL.js +83 -0
- package/web/dist/assets/index-DnKeiDbj.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-BqdAjEjF.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +15 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-3wojLfLk.js +0 -3
- package/web/dist/assets/index-A8YXwnpZ.js +0 -2008
- package/web/dist/assets/index-BwL7qBh6.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
package/bin/pi-web-ui.mjs
CHANGED
|
@@ -28,14 +28,17 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
28
28
|
import { createConnection } from "node:net";
|
|
29
29
|
import { get as httpGet } from "node:http";
|
|
30
30
|
import { createInterface } from "node:readline/promises";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// Dispatch Hub before loading optional plugin/FRP dependencies or the server build.
|
|
32
|
+
if (process.argv[2] === "hub") {
|
|
33
|
+
try {
|
|
34
|
+
const { runHubCliEntry } = await import("./device-hub-cli.mjs");
|
|
35
|
+
await runHubCliEntry(process.argv.slice(3));
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(`[device-hub] ${error.message}`);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
39
42
|
import {
|
|
40
43
|
chmodSync,
|
|
41
44
|
copyFileSync,
|
|
@@ -50,11 +53,21 @@ import {
|
|
|
50
53
|
rmSync,
|
|
51
54
|
writeFileSync,
|
|
52
55
|
} from "node:fs";
|
|
53
|
-
import { homedir, tmpdir, userInfo } from "node:os";
|
|
56
|
+
import { homedir, networkInterfaces, tmpdir, userInfo } from "node:os";
|
|
54
57
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
55
58
|
import { pathToFileURL } from "node:url";
|
|
56
59
|
import { fileURLToPath } from "node:url";
|
|
57
60
|
|
|
61
|
+
const isHubCommand = process.argv[2] === "hub";
|
|
62
|
+
const { frpCmd } = isHubCommand ? {} : await import("./frp-manager.mjs");
|
|
63
|
+
const {
|
|
64
|
+
ensureBackup: ensurePluginBackup,
|
|
65
|
+
restoreBackup: restorePluginBackup,
|
|
66
|
+
checkPluginUpdates,
|
|
67
|
+
resolveRemoteSha,
|
|
68
|
+
compareVersions,
|
|
69
|
+
} = isHubCommand ? {} : await import("../dist/server/plugin-updater.js");
|
|
70
|
+
|
|
58
71
|
const BIN_DIR = dirname(fileURLToPath(import.meta.url));
|
|
59
72
|
/** <pkg>/dist/server/index.js — the actual server entry. */
|
|
60
73
|
const SERVER_ENTRY = join(BIN_DIR, "..", "dist", "server", "index.js");
|
|
@@ -1338,10 +1351,10 @@ function installLaunchd(opts) {
|
|
|
1338
1351
|
mkdirSync(dirname(plist), { recursive: true });
|
|
1339
1352
|
writeFileSync(plist, content);
|
|
1340
1353
|
run("launchctl", ["bootstrap", `gui/${uid()}`, plist]);
|
|
1354
|
+
if (opts.print) return;
|
|
1341
1355
|
console.log(ZH ? `✅ 已安装并启动 launchd 服务 ${label}` : `✅ launchd service installed and started ${label}`);
|
|
1342
1356
|
console.log(ZH ? ` 端口 : ${port}` : ` Port : ${port}`);
|
|
1343
1357
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
1344
|
-
console.log(ZH ? ` 访问 : http://localhost:${port}` : ` URL : http://localhost:${port}`);
|
|
1345
1358
|
console.log(
|
|
1346
1359
|
ZH ? ` 日志 : /tmp/pi-web-ui.log /tmp/pi-web-ui.err` : ` Log : /tmp/pi-web-ui.log /tmp/pi-web-ui.err`,
|
|
1347
1360
|
);
|
|
@@ -1399,7 +1412,6 @@ function installSystemd(opts) {
|
|
|
1399
1412
|
);
|
|
1400
1413
|
console.log(ZH ? ` 端口 : ${port}` : ` Port : ${port}`);
|
|
1401
1414
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
1402
|
-
console.log(ZH ? ` 访问 : http://localhost:${port}` : ` URL : http://localhost:${port}`);
|
|
1403
1415
|
console.log(ZH ? ` 日志 : journalctl -u ${name}.service -f` : ` Log : journalctl -u ${name}.service -f`);
|
|
1404
1416
|
console.log(
|
|
1405
1417
|
ZH
|
|
@@ -1495,7 +1507,6 @@ function installWindows(opts) {
|
|
|
1495
1507
|
console.log(ZH ? ` 窗口 : wscript 隐藏启动,无黑窗` : ` Window : wscript hidden launch, no console`);
|
|
1496
1508
|
console.log(ZH ? ` 端口 : ${port}` : ` Port : ${port}`);
|
|
1497
1509
|
console.log(ZH ? ` 目录 : ${cwd}` : ` Directory : ${cwd}`);
|
|
1498
|
-
console.log(ZH ? ` 访问 : http://localhost:${port}` : ` URL : http://localhost:${port}`);
|
|
1499
1510
|
console.log(ZH ? ` 日志 : ${winLogPath(name)}` : ` Log : ${winLogPath(name)}`);
|
|
1500
1511
|
console.log(
|
|
1501
1512
|
ZH
|
|
@@ -1585,6 +1596,88 @@ function controlCommand(opts, cmd) {
|
|
|
1585
1596
|
});
|
|
1586
1597
|
}
|
|
1587
1598
|
|
|
1599
|
+
function isLocalLoopback(addr) {
|
|
1600
|
+
if (!addr) return false;
|
|
1601
|
+
const s = addr.trim().toLowerCase();
|
|
1602
|
+
return (
|
|
1603
|
+
s === "localhost" ||
|
|
1604
|
+
s.endsWith(".localhost") ||
|
|
1605
|
+
s === "127.0.0.1" ||
|
|
1606
|
+
s.startsWith("127.") ||
|
|
1607
|
+
s === "::1" ||
|
|
1608
|
+
s.startsWith("::ffff:127.")
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
function getLocalLanIpv4s() {
|
|
1613
|
+
const ips = [];
|
|
1614
|
+
try {
|
|
1615
|
+
const ifaces = networkInterfaces();
|
|
1616
|
+
for (const list of Object.values(ifaces)) {
|
|
1617
|
+
if (!list) continue;
|
|
1618
|
+
for (const iface of list) {
|
|
1619
|
+
if (iface && iface.family === "IPv4" && !iface.internal) {
|
|
1620
|
+
ips.push(iface.address);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
} catch {
|
|
1625
|
+
// best-effort
|
|
1626
|
+
}
|
|
1627
|
+
return ips;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
/** 格式化打印服务的访问链接(包含本机、局域网 IP 与 Token / Setup 入口) */
|
|
1631
|
+
function printServiceUrls(port, host, token = "") {
|
|
1632
|
+
const tokenSuffix = token ? `?token=${token}` : "";
|
|
1633
|
+
const isLoopback = !host || isLocalLoopback(host);
|
|
1634
|
+
console.log(
|
|
1635
|
+
ZH
|
|
1636
|
+
? ` 本机访问 : http://127.0.0.1:${port}/${tokenSuffix}`
|
|
1637
|
+
: ` Local URL : http://127.0.0.1:${port}/${tokenSuffix}`,
|
|
1638
|
+
);
|
|
1639
|
+
|
|
1640
|
+
if (!isLoopback) {
|
|
1641
|
+
const lanIps = getLocalLanIpv4s();
|
|
1642
|
+
if (lanIps.length > 0) {
|
|
1643
|
+
for (const ip of lanIps) {
|
|
1644
|
+
console.log(
|
|
1645
|
+
ZH
|
|
1646
|
+
? ` 局域网 : http://${ip}:${port}/${tokenSuffix}`
|
|
1647
|
+
: ` LAN URL : http://${ip}:${port}/${tokenSuffix}`,
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
} else if (host !== "0.0.0.0") {
|
|
1651
|
+
console.log(
|
|
1652
|
+
ZH
|
|
1653
|
+
? ` 访问地址 : http://${host}:${port}/${tokenSuffix}`
|
|
1654
|
+
: ` Host URL : http://${host}:${port}/${tokenSuffix}`,
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
if (token) {
|
|
1659
|
+
console.log(ZH ? ` 访问密钥 : ${token}` : ` Token : ${token}`);
|
|
1660
|
+
}
|
|
1661
|
+
console.log(
|
|
1662
|
+
ZH
|
|
1663
|
+
? ` 配置管理 : http://127.0.0.1:${port}/setup (仅本机)`
|
|
1664
|
+
: ` Setup : http://127.0.0.1:${port}/setup (local only)`,
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/** 轮询等待后台服务就绪并打印包含实时 token 的访问信息 */
|
|
1669
|
+
async function printRunningServiceAccess(opts, host, fallbackToken = "") {
|
|
1670
|
+
const t0 = Date.now();
|
|
1671
|
+
let st = null;
|
|
1672
|
+
while (Date.now() - t0 < 3500) {
|
|
1673
|
+
st = await controlCommand(opts, "status");
|
|
1674
|
+
if (st && st.ok) break;
|
|
1675
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1676
|
+
}
|
|
1677
|
+
const token = (st && typeof st.authToken === "string" ? st.authToken : fallbackToken).trim();
|
|
1678
|
+
printServiceUrls(effectivePort(opts), host, token);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1588
1681
|
/** Append the live server status (via the control socket) to `server status`. */
|
|
1589
1682
|
async function printLiveStatus(opts) {
|
|
1590
1683
|
const st = await controlCommand(opts, "status");
|
|
@@ -1597,6 +1690,10 @@ async function printLiveStatus(opts) {
|
|
|
1597
1690
|
return;
|
|
1598
1691
|
}
|
|
1599
1692
|
console.log(ZH ? " --- 实时状态 (control socket) ---" : " --- live status (control socket) ---");
|
|
1693
|
+
if (st.authToken) {
|
|
1694
|
+
const host = process.env.PI_WEB_HOST || "";
|
|
1695
|
+
printServiceUrls(effectivePort(opts), host, st.authToken);
|
|
1696
|
+
}
|
|
1600
1697
|
console.log(ZH ? ` 版本 : ${st.version} · PID ${st.pid}` : ` Version : ${st.version} · PID ${st.pid}`);
|
|
1601
1698
|
console.log(ZH ? ` 目录 : ${st.cwd}` : ` Directory : ${st.cwd}`);
|
|
1602
1699
|
// 启动来源(server/launch-origin.ts):有 supervisor = 这个进程退出后会被自动
|
|
@@ -3644,7 +3741,7 @@ async function pluginInstallCmd(argv) {
|
|
|
3644
3741
|
}
|
|
3645
3742
|
}
|
|
3646
3743
|
|
|
3647
|
-
function pluginUninstallCmd(argv) {
|
|
3744
|
+
async function pluginUninstallCmd(argv) {
|
|
3648
3745
|
const { opts, positionals } = parseFlags(argv);
|
|
3649
3746
|
if (opts.help || positionals.length !== 1) {
|
|
3650
3747
|
console.log(PLUGIN_HELP);
|
|
@@ -3660,7 +3757,20 @@ function pluginUninstallCmd(argv) {
|
|
|
3660
3757
|
? `未安装插件 "${id}"(pi-web-ui plugins 查看已装列表)`
|
|
3661
3758
|
: `Plugin not installed: "${id}" (pi-web-ui plugins to see installed list)`,
|
|
3662
3759
|
);
|
|
3663
|
-
|
|
3760
|
+
const { removePlugin } = await import("../dist/server/plugin-removal.js");
|
|
3761
|
+
let deferred;
|
|
3762
|
+
try {
|
|
3763
|
+
({ deferred } = removePlugin(pluginDataDir(opts), id));
|
|
3764
|
+
} catch (err) {
|
|
3765
|
+
fail(`${err?.message ?? err}`);
|
|
3766
|
+
}
|
|
3767
|
+
if (deferred) {
|
|
3768
|
+
console.log(
|
|
3769
|
+
ZH
|
|
3770
|
+
? "部分文件仍被进程占用,将在服务重启后清理。"
|
|
3771
|
+
: "Some files are still in use and will be cleaned up after the service restarts.",
|
|
3772
|
+
);
|
|
3773
|
+
}
|
|
3664
3774
|
console.log(
|
|
3665
3775
|
ZH
|
|
3666
3776
|
? `✔ 已卸载插件 ${id} —— 运行中的服务刷新浏览器后消失。`
|
|
@@ -3845,6 +3955,10 @@ async function serverCmd(argv) {
|
|
|
3845
3955
|
ZH ? `不支持的系统服务平台: ${process.platform}` : `Unsupported system service platform: ${process.platform}`,
|
|
3846
3956
|
);
|
|
3847
3957
|
}
|
|
3958
|
+
if (!opts.print) {
|
|
3959
|
+
const fallbackToken = process.env.PI_WEB_TOKEN || "";
|
|
3960
|
+
await printRunningServiceAccess(opts, opts.host ?? process.env.PI_WEB_HOST, fallbackToken);
|
|
3961
|
+
}
|
|
3848
3962
|
break;
|
|
3849
3963
|
}
|
|
3850
3964
|
case "uninstall": {
|
|
@@ -3862,8 +3976,13 @@ async function serverCmd(argv) {
|
|
|
3862
3976
|
break;
|
|
3863
3977
|
}
|
|
3864
3978
|
case "start":
|
|
3979
|
+
case "restart": {
|
|
3980
|
+
controlService(action, opts);
|
|
3981
|
+
const fallbackToken = process.env.PI_WEB_TOKEN || "";
|
|
3982
|
+
await printRunningServiceAccess(opts, opts.host ?? process.env.PI_WEB_HOST, fallbackToken);
|
|
3983
|
+
break;
|
|
3984
|
+
}
|
|
3865
3985
|
case "stop":
|
|
3866
|
-
case "restart":
|
|
3867
3986
|
controlService(action, opts);
|
|
3868
3987
|
break;
|
|
3869
3988
|
case "status":
|
|
@@ -3901,6 +4020,11 @@ async function main() {
|
|
|
3901
4020
|
console.log(HELP);
|
|
3902
4021
|
return;
|
|
3903
4022
|
}
|
|
4023
|
+
if (first === "hub") {
|
|
4024
|
+
const { runHubCli } = await import("./device-hub-cli.mjs");
|
|
4025
|
+
await runHubCli(argv.slice(1));
|
|
4026
|
+
return;
|
|
4027
|
+
}
|
|
3904
4028
|
if (first === "server") {
|
|
3905
4029
|
await serverCmd(argv.slice(1));
|
|
3906
4030
|
return;
|
|
@@ -3914,7 +4038,7 @@ async function main() {
|
|
|
3914
4038
|
return;
|
|
3915
4039
|
}
|
|
3916
4040
|
if (first === "uninstall") {
|
|
3917
|
-
pluginUninstallCmd(argv.slice(1));
|
|
4041
|
+
await pluginUninstallCmd(argv.slice(1));
|
|
3918
4042
|
return;
|
|
3919
4043
|
}
|
|
3920
4044
|
if (first === "plugins" || first === "plugin") {
|
|
@@ -3942,7 +4066,8 @@ async function main() {
|
|
|
3942
4066
|
await startForeground(opts);
|
|
3943
4067
|
}
|
|
3944
4068
|
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
4069
|
+
if (!isHubCommand)
|
|
4070
|
+
main().catch((err) => {
|
|
4071
|
+
console.error(`✖ ${err instanceof Error ? err.message : String(err)}`);
|
|
4072
|
+
process.exit(1);
|
|
4073
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
已在 commit 9e04e099 中彻底修复并闭环:
|
|
2
|
+
|
|
3
|
+
1. **Markdown 链接与图片拦截转写**:在 `web/src/components/Markdown.tsx` 中拦截相对路径(如 `output/summary.md`)和绝对路径,自动转换为受鉴权保护的工作区直链(HTML 文件走 `/api/preview` 沙箱隔离预览,其他文件走 `/api/file` 原生打开/流式播放);
|
|
4
|
+
2. **服务端直开权限完善**:更新 `server/index.ts` 放行合法工作区文本/数据文件(配合 `nosniff` 与沙箱),不再返回 400 阻断;
|
|
5
|
+
3. **适配远程访问**:`present_files` 探测到远程访问时,自动将本地窗口唤醒按钮替换为新标签页打开。
|
|
@@ -18,14 +18,16 @@ import { randomUUID } from "node:crypto";
|
|
|
18
18
|
import { VERSION, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import { ClientStateStore } from "./client-state.js";
|
|
20
20
|
import { ClaimStore } from "./claim-store.js";
|
|
21
|
+
import { isBotExecutionRegistered } from "./device-center/bot-execution.js";
|
|
21
22
|
import { toServiceInfo, launchOrigin } from "./launch-origin.js";
|
|
22
|
-
import { isPseudoClientId, checkPluginCwd } from "./client-id-utils.js";
|
|
23
|
+
import { isPseudoClientId, isOrphanAdoptionExcludedClientId, checkPluginCwd } from "./client-id-utils.js";
|
|
23
24
|
import { pickAdoptableOrphan } from "./orphan-manager.js";
|
|
24
25
|
import { findMostRecentSessionFileFast } from "./session-parser.js";
|
|
25
26
|
import { isRemoteWorkspaceUri, resolveWorkspaceSessionDir } from "./remote-ssh-service.js";
|
|
26
27
|
import { getMaxOpenConversations } from "./agent-formatters.js";
|
|
27
28
|
import { collectSubagentDescendantIds } from "./subagents.js";
|
|
28
29
|
import { pickLatestClientSnapshot } from "./plugin-conversation-view.js";
|
|
30
|
+
import { normalizePluginChatAttachments } from "./plugin-chat-attachments.js";
|
|
29
31
|
import { DEFAULT_PI_CAPABILITIES } from "./engine-capabilities.js";
|
|
30
32
|
import { ClientSession, QuiesceRejectedError, OFFLINE_ROW_TTL_MS, } from "./agent-service.js";
|
|
31
33
|
export class AgentService {
|
|
@@ -590,6 +592,7 @@ export class AgentService {
|
|
|
590
592
|
const acct = String(req?.accountId ?? "default").replace(/[^A-Za-z0-9_-]/g, "") || "default";
|
|
591
593
|
const clientId = `plugin:${safe}:${acct}`;
|
|
592
594
|
const text = String(req?.text ?? "");
|
|
595
|
+
const attachments = normalizePluginChatAttachments(req?.attachments);
|
|
593
596
|
if (!text.trim())
|
|
594
597
|
throw new Error("chatFromPlugin: text 为空");
|
|
595
598
|
if (this.quiesced)
|
|
@@ -602,20 +605,41 @@ export class AgentService {
|
|
|
602
605
|
// miss/已回收时不抛错,回落无头伪客户端(浏览器关着时微信照常可用)。
|
|
603
606
|
const target = String(req?.conversationId ?? "").trim();
|
|
604
607
|
if (target) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
608
|
+
// Conversation ids are local to a client. Prefer this channel's own
|
|
609
|
+
// client; otherwise require an unambiguous target instead of guessing.
|
|
610
|
+
const own = this.clients.get(clientId);
|
|
611
|
+
const ownConv = own?.getConversation(target);
|
|
612
|
+
const hits = [];
|
|
613
|
+
if (own && ownConv)
|
|
614
|
+
hits.push({ owner: own, conv: ownConv, ownerId: clientId });
|
|
615
|
+
else {
|
|
616
|
+
for (const [ownerId, owner] of this.clients) {
|
|
617
|
+
const conv = owner.getConversation(target);
|
|
618
|
+
if (conv)
|
|
619
|
+
hits.push({ owner, conv, ownerId });
|
|
617
620
|
}
|
|
618
|
-
|
|
621
|
+
}
|
|
622
|
+
if (hits.length > 1)
|
|
623
|
+
throw new Error("chatFromPlugin: ambiguous conversation id; rebind the channel");
|
|
624
|
+
if (hits.length === 1) {
|
|
625
|
+
const { owner, conv, ownerId } = hits[0];
|
|
626
|
+
if (req.cwd && resolve(req.cwd) !== resolve(conv.cwd))
|
|
627
|
+
throw new Error("chatFromPlugin: bound conversation cwd differs; start a new channel conversation");
|
|
628
|
+
if (req.model || req.thinkingLevel) {
|
|
629
|
+
// Apply overrides only when the captured conversation is active;
|
|
630
|
+
// these APIs address the owner's active conversation.
|
|
631
|
+
if (owner.readConversationForPlugins()?.conversationId !== conv.id)
|
|
632
|
+
throw new Error("chatFromPlugin: cannot change settings of an inactive bound conversation");
|
|
633
|
+
if (req.model)
|
|
634
|
+
await owner.switchModelOrThrow(req.model);
|
|
635
|
+
if (req.thinkingLevel)
|
|
636
|
+
owner.setThinking(req.thinkingLevel);
|
|
637
|
+
}
|
|
638
|
+
owner.markPluginRun(runId, conv);
|
|
639
|
+
void owner
|
|
640
|
+
.prompt(text, attachments, false, conv)
|
|
641
|
+
.catch((err) => console.error("[plugin chat] prompt failed", err));
|
|
642
|
+
return { conversationId: conv.id, clientId: ownerId, runId };
|
|
619
643
|
}
|
|
620
644
|
}
|
|
621
645
|
// 2. 工作空间:不传回落伪客户端当前目录;传了必须存在且非系统目录。
|
|
@@ -662,9 +686,18 @@ export class AgentService {
|
|
|
662
686
|
/* 打标尽力而为 */
|
|
663
687
|
}
|
|
664
688
|
const conversationId = stampedId || (cs.readConversationForPlugins()?.conversationId ?? "");
|
|
665
|
-
|
|
689
|
+
const conv = cs.getConversation(conversationId);
|
|
690
|
+
void cs.prompt(text, attachments, false, conv).catch((err) => console.error("[plugin chat] prompt failed", err));
|
|
666
691
|
return { conversationId, clientId, runId };
|
|
667
692
|
}
|
|
693
|
+
/** Abort by the stable plugin run token, including after conversation takeover. */
|
|
694
|
+
async abortPluginRun(runId) {
|
|
695
|
+
for (const owner of this.clients.values()) {
|
|
696
|
+
if (owner.findPluginRun(runId))
|
|
697
|
+
return owner.abortPluginRun(runId);
|
|
698
|
+
}
|
|
699
|
+
return { ok: false, error: "Plugin run is no longer active" };
|
|
700
|
+
}
|
|
668
701
|
/** 内置定时任务的无头执行(issue #184,server/scheduler-tasks.ts 的 executor)。
|
|
669
702
|
* 每个任务独立伪客户端 `scheduler:<taskId>`(专属会话连续、无浏览器也能跑);
|
|
670
703
|
* cwd 按任务配置 pin 住(不存在即失败,不默默跑错目录);可选模型/思考强度
|
|
@@ -807,7 +840,7 @@ export class AgentService {
|
|
|
807
840
|
for (const [id, cs] of this.clients) {
|
|
808
841
|
if (id === excludeClientId)
|
|
809
842
|
continue;
|
|
810
|
-
const pseudo =
|
|
843
|
+
const pseudo = isOrphanAdoptionExcludedClientId(id);
|
|
811
844
|
let live = false;
|
|
812
845
|
let streaming = 0;
|
|
813
846
|
let adoptable = false;
|
|
@@ -1078,6 +1111,31 @@ export class AgentService {
|
|
|
1078
1111
|
target.refreshExternalRunning();
|
|
1079
1112
|
}
|
|
1080
1113
|
}
|
|
1114
|
+
/** Locate the live request again after takeover; conversation IDs may have changed. */
|
|
1115
|
+
async navigateQuestion(targetId, id) {
|
|
1116
|
+
const target = this.clients.get(targetId);
|
|
1117
|
+
if (!target)
|
|
1118
|
+
return;
|
|
1119
|
+
for (const [ownerId, source] of this.clients) {
|
|
1120
|
+
if (AgentService.isPseudoClientId(ownerId))
|
|
1121
|
+
continue;
|
|
1122
|
+
const request = source.getQuestionNavigation(id);
|
|
1123
|
+
if (!request || resolve(request.cwd) !== resolve(target.cwd))
|
|
1124
|
+
continue;
|
|
1125
|
+
if (source !== target)
|
|
1126
|
+
await this.takeOverConversation(targetId, ownerId, request.rootConversationId);
|
|
1127
|
+
const moved = target.getQuestionNavigation(id);
|
|
1128
|
+
if (moved)
|
|
1129
|
+
await target.switchConversation(moved.conversationId);
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
target.sendNotice({
|
|
1133
|
+
type: "notice",
|
|
1134
|
+
level: "warning",
|
|
1135
|
+
text: "问卷已结束,无法定位来源",
|
|
1136
|
+
textEn: "The question has ended; its source is no longer available.",
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1081
1139
|
/** Get or create the session for a client, racing attach calls safely. */
|
|
1082
1140
|
async attach(clientId, send) {
|
|
1083
1141
|
let cs = this.clients.get(clientId);
|
|
@@ -1094,9 +1152,9 @@ export class AgentService {
|
|
|
1094
1152
|
// 流式增量经尾部 attachSink 直接推给新 socket)。
|
|
1095
1153
|
// 有其他在线标签时不认领(issue #10 隔离优先);quiesce 排空期也放行
|
|
1096
1154
|
// (这是重连既有工作,不是新工作)。本段无 await,并发 attach 原子。
|
|
1097
|
-
//
|
|
1098
|
-
//
|
|
1099
|
-
const orphan =
|
|
1155
|
+
// 伪客户端(含 device-task- 私有 Bot capability)绝不认领;
|
|
1156
|
+
// 候选端同样排除伪客户端,禁止浏览器接管 Bot 或新任务复用旧 capability。
|
|
1157
|
+
const orphan = isOrphanAdoptionExcludedClientId(clientId) ? null : this.findAdoptableOrphan(clientId);
|
|
1100
1158
|
if (orphan) {
|
|
1101
1159
|
this.clients.delete(orphan.oldId);
|
|
1102
1160
|
// 残骸被本页认领:它的离线行状态随 id 作废(行归到新 id 名下)。
|
|
@@ -1148,9 +1206,9 @@ export class AgentService {
|
|
|
1148
1206
|
// 也无需事后拆 runtime)。之前只拦 running:空闲持有照样恢复出双
|
|
1149
1207
|
// writer,两边轮流发送分叉历史。其他客户端不存在时不扫目录。
|
|
1150
1208
|
let createOpts;
|
|
1151
|
-
const
|
|
1152
|
-
if (
|
|
1153
|
-
//
|
|
1209
|
+
const requiresBlankSession = isOrphanAdoptionExcludedClientId(clientId);
|
|
1210
|
+
if (requiresBlankSession) {
|
|
1211
|
+
// 伪客户端(插件、调度、Canvas、Bot):禁止自动恢复工作区历史或旧任务,强制空白
|
|
1154
1212
|
createOpts = { blank: true };
|
|
1155
1213
|
}
|
|
1156
1214
|
else if (this.clients.size > 0) {
|
|
@@ -1198,6 +1256,11 @@ export class AgentService {
|
|
|
1198
1256
|
detachedSinks.delete(send);
|
|
1199
1257
|
if (detachedSinks.size === 0)
|
|
1200
1258
|
this.pendingDetaches.delete(clientId);
|
|
1259
|
+
if (clientId.startsWith("device-task-") && !isBotExecutionRegistered(clientId) && cs.sinkCount() === 0) {
|
|
1260
|
+
this.clients.delete(clientId);
|
|
1261
|
+
await cs.dispose();
|
|
1262
|
+
return cs;
|
|
1263
|
+
}
|
|
1201
1264
|
}
|
|
1202
1265
|
else {
|
|
1203
1266
|
cs.attachSink(send);
|
|
@@ -1230,6 +1293,18 @@ export class AgentService {
|
|
|
1230
1293
|
for (const cs of this.clients.values())
|
|
1231
1294
|
cs.refreshPluginTools();
|
|
1232
1295
|
}
|
|
1296
|
+
mcpProjectCwds() {
|
|
1297
|
+
return [...new Set([...this.clients.values()].flatMap((cs) => cs.mcpProjectCwds()))];
|
|
1298
|
+
}
|
|
1299
|
+
/** Runtime initialization/reload also updates management UI, including clients without conversations. */
|
|
1300
|
+
refreshMcpProject(cwd) {
|
|
1301
|
+
for (const cs of this.clients.values()) {
|
|
1302
|
+
if (resolve(cs.cwd) !== resolve(cwd))
|
|
1303
|
+
continue;
|
|
1304
|
+
cs.broadcastMcpServers();
|
|
1305
|
+
cs.pushSettings();
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1233
1308
|
/** Browser UI locale report (hello.locale / set_locale): persist per client
|
|
1234
1309
|
* and refresh lang-aware prompts (streaming-safe via ClientSession). */
|
|
1235
1310
|
async setLocale(clientId, locale) {
|
|
@@ -1270,8 +1345,11 @@ export class AgentService {
|
|
|
1270
1345
|
if (cs) {
|
|
1271
1346
|
cs.detachSink(send);
|
|
1272
1347
|
if (cs.sinkCount() === 0) {
|
|
1273
|
-
if (clientId.startsWith("canvas:") ||
|
|
1274
|
-
|
|
1348
|
+
if (clientId.startsWith("canvas:") ||
|
|
1349
|
+
clientId.startsWith("canvas-") ||
|
|
1350
|
+
(clientId.startsWith("device-task-") && !isBotExecutionRegistered(clientId))) {
|
|
1351
|
+
// Bot registration is released only after the executor confirms stop.
|
|
1352
|
+
// Keep uncertain/disconnected executions owned until that confirmation.
|
|
1275
1353
|
this.clients.delete(clientId);
|
|
1276
1354
|
void cs.dispose().catch(() => { });
|
|
1277
1355
|
return;
|