pi-web-ui 0.112.0 → 0.113.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 +38 -1
- package/bin/pi-web-ui.mjs +325 -45
- package/dist/server/agent-service-daemon.js +29 -4
- package/dist/server/agent-service.js +215 -35
- package/dist/server/canvas/canvas-agent-tool.js +2 -0
- package/dist/server/canvas/canvas-orchestrator.js +40 -1
- package/dist/server/canvas/pstack-skills-data.js +498 -0
- package/dist/server/dispatch-domain-handlers.js +36 -11
- package/dist/server/dsh/dsh-agent-service.js +52 -4
- package/dist/server/durable/durable-driver.js +37 -98
- package/dist/server/durable/durable-event-projector.js +253 -0
- package/dist/server/engine-probe.js +35 -11
- package/dist/server/index.js +67 -41
- package/dist/server/model-admin.js +185 -63
- package/dist/server/plugins.js +10 -6
- package/dist/server/remote-ssh-service.js +110 -12
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +36 -48
- package/dist/server/setup-page.js +632 -0
- package/dist/server/skill-discovery.js +361 -59
- package/dist/server/skill-maintenance.js +231 -0
- package/dist/server/skill-tool.js +32 -3
- package/dist/server/soft-cap.js +29 -7
- package/dist/server/subagents.js +246 -31
- package/dist/server/tool-host-factories.js +2 -0
- package/dist/server/tool-manager.js +106 -28
- package/dist/server/universal/drivers/claude-code.js +96 -4
- package/dist/server/universal/universal-session.js +19 -0
- package/package.json +1 -1
- package/plugins/catalog.json +10 -0
- package/web/dist/assets/{TerminalPanel-Dqr1dK28.js → TerminalPanel-3wojLfLk.js} +2 -2
- package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
- package/web/dist/assets/index-BwL7qBh6.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-Dh8BX-lP.js +0 -720
- package/web/dist/assets/index-DqrC1I_a.css +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,42 @@
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.113.0] — 2026-10-28
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **QQ 通道富媒体双向(图片/语音/视频/文件)**:入站附件(`attachments`,腾讯 CDN)下载到工作区 `.pi-qq-media/` 并给 agent 本地路径(语音优先 `voice_wav_url` + 官方 ASR 文本),单件 25MB 上限、失败降级占位;出站给 `qq` 工具补 `image`/`file` 与 `user_openid`/`group_openid`,本地文件自动上传(≤5MB 走 base64 `file_data`,更大走 `upload_prepare` → 分片 PUT → `upload_part_finish` → 合并拿 `file_info`,再 `msg_type=7` 发送),超软限制降级为文件卡片;工作台新增媒体发送与「接收图片/文件落地」开关。频道(子频道)受官方限制只收公网 URL,本地文件明确报错。
|
|
18
|
+
- **通道插件运行归属根治(`host.chat` 回执新增稳定 `runId`)**:微信/钉钉/QQ/Discord/飞书此前靠 `clientId + conversationId` 认领回包,而「过户」会把两者同时改掉(`clientId` 换成浏览器标签页、撞 id 时对话就地改名),导致整轮事件无人认领、只剩「还在执行」后再无下文。现在运行轨迹事件携带不随过户/改名变化的 `runId`,`chatWait` 亦按它唤醒;钉钉/Discord 顺带修复「忽略 `host.chat` 回执、用本地编造会话 id 当键」导致正文从来发不出去的老问题。
|
|
19
|
+
- **画布工作室与技能/工具工作台升级**:P-Stack 技能包、节点抽屉与模板、审查卡点续跑;工具检查器(Tool Inspector)重构与文件差异可视化(统一/分屏/原始三视图、全屏、复制 patch);设置面板重排与 MCP / 技能市场(分类、复制链接、空态引导)。
|
|
20
|
+
- **远程工作台插件(remote-workbench)**:SSH 远程会话、xterm 终端、紧凑视图与工作区 URI,配套 sftp 插件增强。
|
|
21
|
+
- **技能发现与维护**:`skill-discovery` 重写 + `universal-skill-scanner`(`.pi/skills`、`.claude/skills` 目录型/单文件型统一扫描)+ `skill-maintenance` 清理能力。
|
|
22
|
+
- **用户终端持久化**:用户直接创建的交互式终端按客户端/工作区存活,不受单个对话切换与生命周期影响(快照、回放、退出广播都独立登记)。
|
|
23
|
+
- **`subagent(action="dismiss")`**:批量/单个回收已结束的子代理(含 `finished_all`、worktree 脏检查、持久化子代理保护),并同步 UI 列表(#767, #768)。
|
|
24
|
+
- **模型级 `thinkingLevelMap` 推导与保留**:候选采纳器默认勾选现有模型,切换/采纳后不丢思考强度映射(#771, #772)。
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **工具门控改为声明式「管辖权分界」(Authority Boundary)**:`tool-manager` 重构门控合成,恢复会话与重放时保留扩展主动禁用的工具状态,避免重连后被悄悄打开(#777, #779)。
|
|
29
|
+
- **Durable 引擎工具卡改由 `watchEvents` 事件流投影**:新增 `durable-event-projector`,工具卡入参与结果不再读 `pi.live` 私有槽位(原来为空并污染落盘会话),正文与工具卡按提交时间对齐(#774, #775)。
|
|
30
|
+
- **官方插件体系**:browser-use 探测脚本与文档更新;QQ / 微信 / 钉钉 / Discord / 飞书 / sftp 版本号递增(随包热同步生效)。
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- **微信通道连发丢答**:`bindActive`(投递到网页活跃会话)模式下第二条消息会把同一会话里**还在跑那一轮已产出的正文**一起清掉,最终只回「任务完成(无文本输出)」;改为只清没有在跑登记的残留文本(#770)。
|
|
35
|
+
- **Claude Code 引擎 macOS 定位**:自动解析 CLI 可执行路径并完善全局检测与 PATH 扫描(含 nvm/homebrew 场景)。
|
|
36
|
+
- **界面细节**:设置面板格式化、composer 高度自适应与拖拽手柄文案、文件差异卡在流式期间的渲染稳定性。
|
|
37
|
+
|
|
38
|
+
<!-- auto-i18n:start -->
|
|
39
|
+
### i18n
|
|
40
|
+
|
|
41
|
+
- 前端新增 key(36):`composerResizeFixed`、`mcpMarketVisit`、`mcpMarketCopyLink`、`mcpMarketCopied`、`mcpMarketEmpty`、`mcpMarketEmptyClear`、`mcpCatAll`、`mcpCatCn`、`mcpCatMarketplace`、`mcpCatCommunity`、`mcpCatOfficial`、`skillMarketNoticeTitle`、`skillMarketNoticeDesc`、`skillMarketVisit`、`skillMarketCopyLink`、`skillMarketCopied`、`skillMarketEmpty`、`skillMarketEmptyClear`、`skillCatOfficial`、`skillCatMarketplace`、`skillCatCommunity`、`skillCatDirectory`、`diffViewUnified`、`diffViewSplit`、`diffViewRaw`、`diffNewFile`、`diffOpenFile`、`diffCopyContent`、`diffCopyPatch`、`diffStreaming`、`diffEmptyHunks`、`diffFullscreen`、`diffRestoreScreen`、`skillClickToInspect`、`copySkillContent`、`copiedSkillContent`
|
|
42
|
+
- 前端删除 key(34):`mcpBadgeOfficial`、`mcpConfigured`、`mcpAddGlobal`、`mcpAddProject`、`mcpAddGlobalHint`、`mcpAddProjectHint`、`skillCatQuality`、`skillCatWorkflow`、`skillCatArchitecture`、`skillCatDevops`、`skillCatStack`、`skillInspectPrompt`、`skillInstalled`、`skillInstallGlobal`、`skillInstallProject`、`skillInstallGlobalHint`、`skillInstallProjectHint`、`mcpSourceSelectLabel`、`mcpSourceSmithery`、`mcpSourceGithub`、`mcpSourceCustom`、`mcpSourceCustomPlaceholder`、`mcpMarketLoading`、`mcpMarketRetry`、`skillRepoSelect`、`skillRepoDefault`、`skillRepoCustom`、`skillRepoCustomPlaceholder`、`skillMarketLoading`、`skillMarketRetry`、`toolInspectorOutput`、`toolInspectorError`、`toolInspectorToggleRaw`、`toolInspectorTogglePreview`
|
|
43
|
+
- 前端中文变更(8):`composerResize`、`mcpMarketSearchPlaceholder`、`skillEmptyDesc`、`skillMarketSearchPlaceholder`、`skillCatAll`、`skillFullTextShort`、`skillInspectModalTitle`、`skillContentLoading`
|
|
44
|
+
- 前端英文变更(7):`composerResize`、`mcpMarketSearchPlaceholder`、`skillEmptyDesc`、`skillMarketSearchPlaceholder`、`skillCatAll`、`skillFullTextShort`、`skillContentLoading`
|
|
45
|
+
- 服务端新增 key(14):`subagents.dismiss.unsupported`、`subagents.dismiss.missing.target`、`subagents.dismiss.finished_all.empty`、`subagents.dismiss.not_found`、`subagents.dismiss.self`、`subagents.dismiss.active`、`subagents.dismiss.not_descendant`、`subagents.dismiss.persisted`、`subagents.dismiss.running`、`subagents.dismiss.worktree.dirty`、`subagents.dismiss.failed`、`subagents.dismiss.success.single`、`subagents.dismiss.none`、`subagents.dismiss.success.batch`
|
|
46
|
+
- 服务端文案变更(2):`subagents.action.missing`、`subagents.action.unknown`
|
|
47
|
+
<!-- auto-i18n:end -->
|
|
48
|
+
|
|
13
49
|
## [0.112.0] — 2026-10-26
|
|
14
50
|
|
|
15
51
|
### Added
|
|
@@ -1959,7 +1995,8 @@ when?, children?}`,也收 `topbar` / `settings` 这类简写别名);宿主
|
|
|
1959
1995
|
- 0.35.1(2026-08-27):编辑重问保留附件(#18)+ 全窗口拖放(#19)。
|
|
1960
1996
|
- 0.29.0(2026-08-23):全局搜索弹窗(Ctrl+K)+ 消息列表惰性窗口化。
|
|
1961
1997
|
|
|
1962
|
-
[Unreleased]: https://github.com/xing-shuyin/pi-web-ui/compare/v0.
|
|
1998
|
+
[Unreleased]: https://github.com/xing-shuyin/pi-web-ui/compare/v0.113.0...main
|
|
1999
|
+
[0.113.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.113.0
|
|
1963
2000
|
[0.112.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.112.0
|
|
1964
2001
|
[0.111.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.111.0
|
|
1965
2002
|
[0.108.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.108.0
|
package/bin/pi-web-ui.mjs
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
restoreBackup as restorePluginBackup,
|
|
35
35
|
checkPluginUpdates,
|
|
36
36
|
resolveRemoteSha,
|
|
37
|
+
compareVersions,
|
|
37
38
|
} from "../dist/server/plugin-updater.js";
|
|
38
39
|
import {
|
|
39
40
|
chmodSync,
|
|
@@ -279,6 +280,7 @@ function parseFlags(argv) {
|
|
|
279
280
|
dir: undefined,
|
|
280
281
|
template: undefined,
|
|
281
282
|
withTest: false,
|
|
283
|
+
remote: false,
|
|
282
284
|
help: false,
|
|
283
285
|
};
|
|
284
286
|
const positionals = [];
|
|
@@ -353,6 +355,9 @@ function parseFlags(argv) {
|
|
|
353
355
|
case "--with-test":
|
|
354
356
|
opts.withTest = true;
|
|
355
357
|
break;
|
|
358
|
+
case "--remote":
|
|
359
|
+
opts.remote = true;
|
|
360
|
+
break;
|
|
356
361
|
case "--help":
|
|
357
362
|
case "-h":
|
|
358
363
|
opts.help = true;
|
|
@@ -1291,7 +1296,18 @@ function serviceEnv(port, cwd, dataDir, engine, host, agentDir, service = {}) {
|
|
|
1291
1296
|
}
|
|
1292
1297
|
// Interactive Windows tasks inherit the user's PATH; only systemd/launchd
|
|
1293
1298
|
// run with a minimal environment that needs an explicit PATH.
|
|
1294
|
-
if (!isWin)
|
|
1299
|
+
if (!isWin) {
|
|
1300
|
+
const defaultPath =
|
|
1301
|
+
process.platform === "darwin"
|
|
1302
|
+
? "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
|
|
1303
|
+
: "/usr/local/bin:/usr/bin:/bin";
|
|
1304
|
+
const currentPath = process.env.PATH ?? defaultPath;
|
|
1305
|
+
if (process.platform === "darwin" && !currentPath.includes("/opt/homebrew/bin")) {
|
|
1306
|
+
env.PATH = `/opt/homebrew/bin:/usr/local/bin:${currentPath}`;
|
|
1307
|
+
} else {
|
|
1308
|
+
env.PATH = currentPath;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1295
1311
|
// Same for the locale: launchd/systemd drop LANG/LC_ALL, and a C-locale
|
|
1296
1312
|
// shell garbles multibyte input in the terminal (UTF-8 continuation
|
|
1297
1313
|
// bytes 0x80–0x9F rendered as C1 control chars). Bake the installing
|
|
@@ -1877,6 +1893,7 @@ const PLUGIN_HELP = ZH
|
|
|
1877
1893
|
--name <id> 插件目录名/id(默认取仓库名或 manifest.id,仅限字母数字-_)
|
|
1878
1894
|
--data-dir <dir> 数据目录(默认 ~/.pi-web 或 $PI_WEB_DATA_DIR)
|
|
1879
1895
|
--force 目标目录已存在时覆盖(覆盖前自动备份旧版本)
|
|
1896
|
+
--remote 强制从远端拉取最新代码(跳过本地随包内置插件快速路径)
|
|
1880
1897
|
--build 强制源码构建:在隔离临时目录里按插件声明安装构建依赖并编译
|
|
1881
1898
|
(manifest.build 或 package.json 的 scripts.build),
|
|
1882
1899
|
成功且产物齐全后才替换目标目录,失败不留半装状态
|
|
@@ -1921,6 +1938,7 @@ Source formats (choose one):
|
|
|
1921
1938
|
--name <id> plugin directory name/id (default: repo name or manifest.id; alphanumeric -_ only)
|
|
1922
1939
|
--data-dir <dir> data directory (default ~/.pi-web or $PI_WEB_DATA_DIR)
|
|
1923
1940
|
--force overwrite if target directory exists (auto-backup before overwrite)
|
|
1941
|
+
--remote force pulling from remote (skip local bundled builtin fast path)
|
|
1924
1942
|
--build force source build: install build deps and compile in an isolated temp directory
|
|
1925
1943
|
(manifest.build or package.json scripts.build),
|
|
1926
1944
|
replaces target only on success with complete artifacts; no partial state on failure
|
|
@@ -1971,10 +1989,34 @@ function parsePluginSource(rawSpec) {
|
|
|
1971
1989
|
if (url) [, spec] = url;
|
|
1972
1990
|
}
|
|
1973
1991
|
const segs = spec.split("/").filter(Boolean);
|
|
1974
|
-
if (segs.length < 2)
|
|
1992
|
+
if (segs.length < 2) {
|
|
1993
|
+
// 单段名称(如 browser-use):若本地随包官方插件或 catalog 存在该 id,自动补齐为官方插件源
|
|
1994
|
+
if (segs.length === 1 && PLUGIN_ID_RE.test(segs[0])) {
|
|
1995
|
+
const id = segs[0];
|
|
1996
|
+
const pkgRoot = resolve(BIN_DIR, "..");
|
|
1997
|
+
const catalogPath = join(pkgRoot, "plugins", "catalog.json");
|
|
1998
|
+
const pluginDir = join(pkgRoot, "plugins", id);
|
|
1999
|
+
let isOfficial = existsSync(join(pluginDir, "manifest.json"));
|
|
2000
|
+
if (!isOfficial && existsSync(catalogPath)) {
|
|
2001
|
+
try {
|
|
2002
|
+
const cat = JSON.parse(readFileSync(catalogPath, "utf8"));
|
|
2003
|
+
if (Array.isArray(cat) && cat.some((e) => e?.id === id)) isOfficial = true;
|
|
2004
|
+
} catch {}
|
|
2005
|
+
}
|
|
2006
|
+
if (isOfficial) {
|
|
2007
|
+
return {
|
|
2008
|
+
owner: "xing-shuyin",
|
|
2009
|
+
repo: "pi-web-ui",
|
|
2010
|
+
ref,
|
|
2011
|
+
subpath: `plugins/${id}`,
|
|
2012
|
+
cloneUrl: "https://github.com/xing-shuyin/pi-web-ui.git",
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1975
2016
|
fail(
|
|
1976
2017
|
ZH ? `无法识别的插件源 "${rawSpec}"\n${PLUGIN_HELP}` : `Unrecognized plugin source "${rawSpec}"\n${PLUGIN_HELP}`,
|
|
1977
2018
|
);
|
|
2019
|
+
}
|
|
1978
2020
|
for (const s of segs) {
|
|
1979
2021
|
if (s === "." || s === "..")
|
|
1980
2022
|
fail(
|
|
@@ -2014,28 +2056,172 @@ function cleanStalePluginTmpDirs() {
|
|
|
2014
2056
|
} catch {}
|
|
2015
2057
|
}
|
|
2016
2058
|
|
|
2017
|
-
/**
|
|
2018
|
-
|
|
2059
|
+
/**
|
|
2060
|
+
* 尝试定位随包自带的内置官方插件目录。
|
|
2061
|
+
* 命中条件:
|
|
2062
|
+
* 1. 未开启强制远端拉取标志(opts.remote / PI_WEB_PLUGIN_FORCE_REMOTE);
|
|
2063
|
+
* 2. 未显式指定非主干 git ref(除 main/master/HEAD 之外的 ref 说明用户想试特定提交);
|
|
2064
|
+
* 3. 属于官方仓库(xing-shuyin/pi-web-ui)的 plugins/<id> 子路径,且随包目录存在合法 manifest.json。
|
|
2065
|
+
*/
|
|
2066
|
+
function resolveLocalBuiltinPluginDir(rawSpec, src, opts = {}) {
|
|
2067
|
+
if (opts.remote === true || process.env.PI_WEB_PLUGIN_FORCE_REMOTE === "1") return null;
|
|
2068
|
+
if (src?.ref && src.ref !== "main" && src.ref !== "master" && src.ref !== "HEAD") return null;
|
|
2069
|
+
|
|
2070
|
+
const pkgRoot = resolve(BIN_DIR, "..");
|
|
2071
|
+
let pluginSubdir = null;
|
|
2072
|
+
|
|
2073
|
+
if (src?.owner === "xing-shuyin" && src?.repo === "pi-web-ui" && src?.subpath) {
|
|
2074
|
+
pluginSubdir = src.subpath.startsWith("plugins/") ? src.subpath.slice("plugins/".length) : src.subpath;
|
|
2075
|
+
} else if (!src && typeof rawSpec === "string" && !rawSpec.includes("/") && PLUGIN_ID_RE.test(rawSpec.trim())) {
|
|
2076
|
+
pluginSubdir = rawSpec.trim();
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
if (!pluginSubdir) return null;
|
|
2080
|
+
const localDir = join(pkgRoot, "plugins", pluginSubdir);
|
|
2081
|
+
if (existsSync(join(localDir, "manifest.json"))) {
|
|
2082
|
+
return localDir;
|
|
2083
|
+
}
|
|
2084
|
+
return null;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* 把仓库拉到 tmpDir 并返回检出根目录。
|
|
2089
|
+
* 优化策略:
|
|
2090
|
+
* 1. 共享缓存复用:同一批量操作/同源仓库共享检出,增量 sparse-checkout add,杜绝反复 clone;
|
|
2091
|
+
* 2. 稀疏拉取(Sparse Checkout + Blobless filter):只拉取元数据与目标子目录,免除全量下载数十兆整仓;
|
|
2092
|
+
* 3. 健壮降级:稀疏失败平滑降级常规 shallow clone,再失败回退 tarball 直连。
|
|
2093
|
+
*/
|
|
2094
|
+
async function acquireRepo(src, tmpDir, opts = {}) {
|
|
2095
|
+
const sharedCache = opts.sharedCache;
|
|
2096
|
+
const cacheKey = sharedCache ? `${src.cloneUrl}#${src.ref || "HEAD"}` : null;
|
|
2097
|
+
const normalizedSubpath = src.subpath ? src.subpath.split(/[\\/]/).filter(Boolean).join("/") : null;
|
|
2098
|
+
|
|
2099
|
+
// 1. 尝试从共享缓存中复用已有检出
|
|
2100
|
+
if (sharedCache && cacheKey && sharedCache.has(cacheKey)) {
|
|
2101
|
+
const cached = sharedCache.get(cacheKey);
|
|
2102
|
+
if (existsSync(cached.dir)) {
|
|
2103
|
+
if (!normalizedSubpath || (cached.subpaths && cached.subpaths.has(normalizedSubpath))) {
|
|
2104
|
+
console.log(
|
|
2105
|
+
ZH
|
|
2106
|
+
? `· 复用已拉取仓库 ${src.cloneUrl}${normalizedSubpath ? ` (${normalizedSubpath})` : ""}`
|
|
2107
|
+
: `· Reusing cached repo ${src.cloneUrl}${normalizedSubpath ? ` (${normalizedSubpath})` : ""}`,
|
|
2108
|
+
);
|
|
2109
|
+
return cached.dir;
|
|
2110
|
+
}
|
|
2111
|
+
if (cached.isSparse && normalizedSubpath) {
|
|
2112
|
+
console.log(
|
|
2113
|
+
ZH
|
|
2114
|
+
? `· 复用已拉取仓库,增量检出 ${normalizedSubpath}…`
|
|
2115
|
+
: `· Reusing cached repo, incrementally checking out ${normalizedSubpath}…`,
|
|
2116
|
+
);
|
|
2117
|
+
const addRes = spawnSync("git", ["sparse-checkout", "add", normalizedSubpath], {
|
|
2118
|
+
cwd: cached.dir,
|
|
2119
|
+
stdio: "inherit",
|
|
2120
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" },
|
|
2121
|
+
timeout: Number(process.env.PI_WEB_GIT_TIMEOUT_MS) || 45_000,
|
|
2122
|
+
});
|
|
2123
|
+
if (addRes.status === 0) {
|
|
2124
|
+
cached.subpaths.add(normalizedSubpath);
|
|
2125
|
+
return cached.dir;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2019
2131
|
const dst = join(tmpDir, "src");
|
|
2020
2132
|
const hasGit = spawnSync("git", ["--version"], { stdio: "ignore", timeout: 10_000 }).status === 0;
|
|
2021
2133
|
if (hasGit) {
|
|
2022
2134
|
const gitTimeout = Number(process.env.PI_WEB_GIT_TIMEOUT_MS) || 45_000;
|
|
2135
|
+
const gitEnv = { ...process.env, GIT_TERMINAL_PROMPT: "0", GCM_INTERACTIVE: "never" };
|
|
2136
|
+
|
|
2137
|
+
// 2. 稀疏拉取:当指定了 subpath 时,优先尝试 --filter=blob:none --sparse
|
|
2138
|
+
if (normalizedSubpath) {
|
|
2139
|
+
const sparseArgs = [
|
|
2140
|
+
"-c",
|
|
2141
|
+
"connect.timeout=15",
|
|
2142
|
+
"clone",
|
|
2143
|
+
"--depth",
|
|
2144
|
+
"1",
|
|
2145
|
+
"--filter=blob:none",
|
|
2146
|
+
"--sparse",
|
|
2147
|
+
"--no-checkout",
|
|
2148
|
+
];
|
|
2149
|
+
if (src.ref) sparseArgs.push("--branch", src.ref);
|
|
2150
|
+
sparseArgs.push(src.cloneUrl, dst);
|
|
2151
|
+
console.log(
|
|
2152
|
+
`· git clone --depth 1 --filter=blob:none --sparse ${src.cloneUrl}${src.ref ? ` (${src.ref})` : ""} [${normalizedSubpath}]`,
|
|
2153
|
+
);
|
|
2154
|
+
const cloneRes = spawnSync("git", sparseArgs, {
|
|
2155
|
+
stdio: "inherit",
|
|
2156
|
+
env: gitEnv,
|
|
2157
|
+
timeout: gitTimeout,
|
|
2158
|
+
});
|
|
2159
|
+
if (cloneRes.status === 0 && existsSync(dst)) {
|
|
2160
|
+
const setRes = spawnSync("git", ["sparse-checkout", "set", normalizedSubpath], {
|
|
2161
|
+
cwd: dst,
|
|
2162
|
+
stdio: "inherit",
|
|
2163
|
+
env: gitEnv,
|
|
2164
|
+
timeout: gitTimeout,
|
|
2165
|
+
});
|
|
2166
|
+
if (setRes.status === 0) {
|
|
2167
|
+
const coRes = spawnSync("git", ["checkout"], {
|
|
2168
|
+
cwd: dst,
|
|
2169
|
+
stdio: "inherit",
|
|
2170
|
+
env: gitEnv,
|
|
2171
|
+
timeout: gitTimeout,
|
|
2172
|
+
});
|
|
2173
|
+
if (coRes.status === 0 && existsSync(dst)) {
|
|
2174
|
+
if (sharedCache && cacheKey) {
|
|
2175
|
+
sharedCache.set(cacheKey, {
|
|
2176
|
+
dir: dst,
|
|
2177
|
+
tmpDir,
|
|
2178
|
+
isSparse: true,
|
|
2179
|
+
subpaths: new Set([normalizedSubpath]),
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
return dst;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
// 稀疏拉取失败,清理已产生的残骸,准备降级
|
|
2187
|
+
if (existsSync(dst)) {
|
|
2188
|
+
try {
|
|
2189
|
+
rmSync(dst, { recursive: true, force: true });
|
|
2190
|
+
} catch {}
|
|
2191
|
+
}
|
|
2192
|
+
console.log(
|
|
2193
|
+
ZH ? "· 稀疏拉取不可用,降级为常规 git clone…" : "· Sparse checkout failed, falling back to regular git clone…",
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
// 3. 常规 shallow clone(未指定 subpath 或稀疏拉取失败时的降级通路)
|
|
2023
2198
|
const args = ["-c", "connect.timeout=15", "clone", "--depth", "1", "--single-branch"];
|
|
2024
2199
|
if (src.ref) args.push("--branch", src.ref);
|
|
2025
2200
|
args.push(src.cloneUrl, dst);
|
|
2026
2201
|
console.log(`· git clone --depth 1 ${src.cloneUrl}${src.ref ? ` (${src.ref})` : ""}`);
|
|
2027
2202
|
const res = spawnSync("git", args, {
|
|
2028
2203
|
stdio: "inherit",
|
|
2029
|
-
env:
|
|
2204
|
+
env: gitEnv,
|
|
2030
2205
|
timeout: gitTimeout,
|
|
2031
2206
|
});
|
|
2032
|
-
if (res.status === 0 && existsSync(dst))
|
|
2207
|
+
if (res.status === 0 && existsSync(dst)) {
|
|
2208
|
+
if (sharedCache && cacheKey) {
|
|
2209
|
+
sharedCache.set(cacheKey, {
|
|
2210
|
+
dir: dst,
|
|
2211
|
+
tmpDir,
|
|
2212
|
+
isSparse: false,
|
|
2213
|
+
subpaths: normalizedSubpath ? new Set([normalizedSubpath]) : new Set(),
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
return dst;
|
|
2217
|
+
}
|
|
2033
2218
|
console.log(
|
|
2034
2219
|
ZH
|
|
2035
2220
|
? "· git clone 失败,回退到 tarball 直连下载…"
|
|
2036
2221
|
: "· git clone failed, falling back to direct tarball download…",
|
|
2037
2222
|
);
|
|
2038
2223
|
}
|
|
2224
|
+
|
|
2039
2225
|
const url = `https://codeload.github.com/${src.owner}/${src.repo}/tar.gz/${src.ref || "HEAD"}`;
|
|
2040
2226
|
console.log(ZH ? `· 下载 ${url}` : `· Downloading ${url}`);
|
|
2041
2227
|
// 注意:这里不用 fail()/process.exit —— async 上下文里还有未关闭的 socket 时
|
|
@@ -2108,9 +2294,9 @@ function findManifestDirs(root) {
|
|
|
2108
2294
|
function locatePluginRoot(checkout, subpath, repoLabel) {
|
|
2109
2295
|
if (subpath) {
|
|
2110
2296
|
const dir = join(checkout, ...subpath.split("/"));
|
|
2111
|
-
if (
|
|
2112
|
-
|
|
2113
|
-
|
|
2297
|
+
if (existsSync(join(dir, "manifest.json"))) return dir;
|
|
2298
|
+
if (existsSync(join(checkout, "manifest.json"))) return checkout;
|
|
2299
|
+
fail(ZH ? `子目录 "${subpath}" 里没有 manifest.json` : `Subdirectory "${subpath}" has no manifest.json`);
|
|
2114
2300
|
}
|
|
2115
2301
|
if (existsSync(join(checkout, "manifest.json"))) return checkout;
|
|
2116
2302
|
const hits = findManifestDirs(checkout);
|
|
@@ -2282,19 +2468,86 @@ async function confirmSourceBuild(plan) {
|
|
|
2282
2468
|
* 覆盖(备份+保留 config.json)→ 落盘 → 记录来源/sha。
|
|
2283
2469
|
* 失败抛 Error(目录模式逐条 try/catch 继续下一条,单源模式由调用方转 fail)。
|
|
2284
2470
|
*/
|
|
2285
|
-
async function installOnePlugin({
|
|
2471
|
+
async function installOnePlugin({
|
|
2472
|
+
rawSpec,
|
|
2473
|
+
name,
|
|
2474
|
+
force,
|
|
2475
|
+
build,
|
|
2476
|
+
noBuild,
|
|
2477
|
+
dataDir,
|
|
2478
|
+
isCatalog = false,
|
|
2479
|
+
sharedCache = null,
|
|
2480
|
+
remote = false,
|
|
2481
|
+
}) {
|
|
2286
2482
|
cleanStalePluginTmpDirs();
|
|
2287
2483
|
const pluginsDir = join(dataDir, "plugins");
|
|
2288
|
-
|
|
2484
|
+
let localCandidate = rawSpec;
|
|
2485
|
+
if (/^file:\/\//i.test(rawSpec)) {
|
|
2486
|
+
try {
|
|
2487
|
+
localCandidate = fileURLToPath(rawSpec);
|
|
2488
|
+
} catch {
|
|
2489
|
+
localCandidate = rawSpec.replace(/^file:\/\//i, "");
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
localCandidate = resolve(localCandidate);
|
|
2289
2493
|
const isLocal = existsSync(localCandidate);
|
|
2290
2494
|
const src = isLocal ? null : parsePluginSource(rawSpec);
|
|
2495
|
+
|
|
2496
|
+
// 随包内置插件快速路径:若随包已自带官方插件且满足版本条件,优先走本地快速通路
|
|
2497
|
+
const localBuiltinDir = isLocal ? null : resolveLocalBuiltinPluginDir(rawSpec, src, { remote });
|
|
2498
|
+
let fastPathCandidate = null;
|
|
2499
|
+
if (localBuiltinDir) {
|
|
2500
|
+
const sourceName = src?.subpath ? src.subpath.split("/").pop() : src?.repo;
|
|
2501
|
+
const fallbackId =
|
|
2502
|
+
String(name ?? sourceName)
|
|
2503
|
+
.replace(/[^A-Za-z0-9_-]/g, "-")
|
|
2504
|
+
.replace(/^-+|-+$/g, "") || "plugin";
|
|
2505
|
+
const id = name ?? fallbackId;
|
|
2506
|
+
const target = join(pluginsDir, id);
|
|
2507
|
+
if (!existsSync(target)) {
|
|
2508
|
+
// 未安装:全新安装直接采用本地随包
|
|
2509
|
+
fastPathCandidate = localBuiltinDir;
|
|
2510
|
+
} else if (force) {
|
|
2511
|
+
// 覆盖更新:对比随包版本与已装版本
|
|
2512
|
+
try {
|
|
2513
|
+
const tgtM = JSON.parse(readFileSync(join(target, "manifest.json"), "utf8"));
|
|
2514
|
+
const srcM = JSON.parse(readFileSync(join(localBuiltinDir, "manifest.json"), "utf8"));
|
|
2515
|
+
if (srcM?.version && tgtM?.version && compareVersions(srcM.version, tgtM.version) > 0) {
|
|
2516
|
+
// 随包版本比已装版本更新(刚升级了主程序),优先直接使用本地随包
|
|
2517
|
+
fastPathCandidate = localBuiltinDir;
|
|
2518
|
+
}
|
|
2519
|
+
} catch {}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2291
2523
|
const tmp = mkdtempSync(join(tmpdir(), "pi-web-ui-plugin-"));
|
|
2292
2524
|
try {
|
|
2293
2525
|
let checkout;
|
|
2294
|
-
|
|
2295
|
-
checkout =
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2526
|
+
if (isLocal) {
|
|
2527
|
+
checkout = localCandidate;
|
|
2528
|
+
} else if (fastPathCandidate) {
|
|
2529
|
+
checkout = fastPathCandidate;
|
|
2530
|
+
console.log(
|
|
2531
|
+
ZH
|
|
2532
|
+
? `· 优先使用本地随包内置插件: ${relative(resolve(BIN_DIR, ".."), checkout).replace(/\\/g, "/")}`
|
|
2533
|
+
: `· Using local bundled plugin: ${relative(resolve(BIN_DIR, ".."), checkout).replace(/\\/g, "/")}`,
|
|
2534
|
+
);
|
|
2535
|
+
} else {
|
|
2536
|
+
try {
|
|
2537
|
+
checkout = await acquireRepo(src, tmp, { sharedCache });
|
|
2538
|
+
} catch (err) {
|
|
2539
|
+
// 若远端拉取失败,且属于官方插件,优雅回退到本地随包(离线与断网容错保护)
|
|
2540
|
+
if (localBuiltinDir && existsSync(join(localBuiltinDir, "manifest.json"))) {
|
|
2541
|
+
console.warn(
|
|
2542
|
+
ZH
|
|
2543
|
+
? `⚠ 远端拉取失败(${err?.message ?? err}),回退到本地随包内置插件…`
|
|
2544
|
+
: `⚠ Remote fetch failed (${err?.message ?? err}), falling back to bundled local plugin…`,
|
|
2545
|
+
);
|
|
2546
|
+
checkout = localBuiltinDir;
|
|
2547
|
+
} else {
|
|
2548
|
+
throw new Error(`${err?.message ?? err}`);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2298
2551
|
}
|
|
2299
2552
|
const repoLabel = isLocal ? localCandidate : `${src.owner}/${src.repo}`;
|
|
2300
2553
|
const pluginRoot = locatePluginRoot(checkout, src?.subpath, repoLabel);
|
|
@@ -2445,10 +2698,22 @@ async function installOnePlugin({ rawSpec, name, force, build, noBuild, dataDir,
|
|
|
2445
2698
|
}
|
|
2446
2699
|
return { id, target, manifest, buildMode: decision.mode };
|
|
2447
2700
|
} finally {
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2701
|
+
// 若当前 tmp 正在被 sharedCache 共享复用,不在此清理,留给批量操作统一释放
|
|
2702
|
+
let isCached = false;
|
|
2703
|
+
if (sharedCache) {
|
|
2704
|
+
for (const c of sharedCache.values()) {
|
|
2705
|
+
if (c.tmpDir === tmp) {
|
|
2706
|
+
isCached = true;
|
|
2707
|
+
break;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if (!isCached) {
|
|
2712
|
+
try {
|
|
2713
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
2714
|
+
} catch {
|
|
2715
|
+
/* Windows 等平台杀毒/进程占用可能抛 EBUSY,不应翻转已成功的安装 */
|
|
2716
|
+
}
|
|
2452
2717
|
}
|
|
2453
2718
|
}
|
|
2454
2719
|
}
|
|
@@ -2637,33 +2902,47 @@ async function installCatalogCmd(opts) {
|
|
|
2637
2902
|
let okCount = 0;
|
|
2638
2903
|
let failCount = 0;
|
|
2639
2904
|
let skipCount = 0;
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2905
|
+
const sharedCache = new Map();
|
|
2906
|
+
try {
|
|
2907
|
+
for (const e of entries) {
|
|
2908
|
+
if (existsSync(join(pluginsDir, e.id)) && !opts.force) {
|
|
2909
|
+
console.log(
|
|
2910
|
+
ZH
|
|
2911
|
+
? `· 跳过 ${e.id}(已安装,加 --force 更新)`
|
|
2912
|
+
: `· Skipping ${e.id} (already installed, use --force to update)`,
|
|
2913
|
+
);
|
|
2914
|
+
skipCount++;
|
|
2915
|
+
continue;
|
|
2916
|
+
}
|
|
2917
|
+
try {
|
|
2918
|
+
await installOnePlugin({
|
|
2919
|
+
rawSpec: e.source,
|
|
2920
|
+
name: e.id,
|
|
2921
|
+
force: true,
|
|
2922
|
+
build: opts.build === true,
|
|
2923
|
+
noBuild: opts.noBuild === true,
|
|
2924
|
+
dataDir,
|
|
2925
|
+
isCatalog: true,
|
|
2926
|
+
sharedCache,
|
|
2927
|
+
remote: opts.remote === true,
|
|
2928
|
+
});
|
|
2929
|
+
console.log(ZH ? `✔ ${e.id} 安装成功` : `✔ ${e.id} installed`);
|
|
2930
|
+
okCount++;
|
|
2931
|
+
} catch (err) {
|
|
2932
|
+
console.error(
|
|
2933
|
+
ZH ? `✖ ${e.id} 安装失败:${err?.message ?? err}` : `✖ ${e.id} failed to install: ${err?.message ?? err}`,
|
|
2934
|
+
);
|
|
2935
|
+
failCount++;
|
|
2936
|
+
}
|
|
2649
2937
|
}
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
isCatalog: true,
|
|
2659
|
-
});
|
|
2660
|
-
console.log(ZH ? `✔ ${e.id} 安装成功` : `✔ ${e.id} installed`);
|
|
2661
|
-
okCount++;
|
|
2662
|
-
} catch (err) {
|
|
2663
|
-
console.error(
|
|
2664
|
-
ZH ? `✖ ${e.id} 安装失败:${err?.message ?? err}` : `✖ ${e.id} failed to install: ${err?.message ?? err}`,
|
|
2665
|
-
);
|
|
2666
|
-
failCount++;
|
|
2938
|
+
} finally {
|
|
2939
|
+
// 统一清理同批任务复用的共享缓存检出目录
|
|
2940
|
+
for (const entry of sharedCache.values()) {
|
|
2941
|
+
if (entry.tmpDir) {
|
|
2942
|
+
try {
|
|
2943
|
+
rmSync(entry.tmpDir, { recursive: true, force: true });
|
|
2944
|
+
} catch {}
|
|
2945
|
+
}
|
|
2667
2946
|
}
|
|
2668
2947
|
}
|
|
2669
2948
|
console.log(
|
|
@@ -3346,6 +3625,7 @@ async function pluginInstallCmd(argv) {
|
|
|
3346
3625
|
build: opts.build === true,
|
|
3347
3626
|
noBuild: opts.noBuild === true,
|
|
3348
3627
|
dataDir: pluginDataDir(opts),
|
|
3628
|
+
remote: opts.remote === true,
|
|
3349
3629
|
});
|
|
3350
3630
|
console.log(
|
|
3351
3631
|
ZH
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { join, resolve } from "node:path";
|
|
16
16
|
import { statSync } from "node:fs";
|
|
17
|
+
import { randomUUID } from "node:crypto";
|
|
17
18
|
import { VERSION, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
18
19
|
import { ClientStateStore } from "./client-state.js";
|
|
19
20
|
import { ClaimStore } from "./claim-store.js";
|
|
@@ -593,13 +594,29 @@ export class AgentService {
|
|
|
593
594
|
throw new Error("chatFromPlugin: text 为空");
|
|
594
595
|
if (this.quiesced)
|
|
595
596
|
throw new QuiesceRejectedError("插件无头调用被拒绝,请等服务器恢复后重试");
|
|
597
|
+
// 本轮运行的稳定标识:随该轮所有 run 事件下发。为何需要:过户会把对话搬到
|
|
598
|
+
// 别的客户端会话(clientId 变),目标会话已有同名 id 时还会就地改名
|
|
599
|
+
// (conversationId 变)——两个键全失效,通道插件靠它认领自己的回包。
|
|
600
|
+
const runId = `pr-${randomUUID()}`;
|
|
596
601
|
// 1. 绑定已有会话:steer 语义投递,网页端实时可见(微信当远程遥控器用)。
|
|
597
602
|
// miss/已回收时不抛错,回落无头伪客户端(浏览器关着时微信照常可用)。
|
|
598
603
|
const target = String(req?.conversationId ?? "").trim();
|
|
599
604
|
if (target) {
|
|
600
605
|
const w = await this.wakeConversation(target, text);
|
|
601
|
-
if (w.ok)
|
|
602
|
-
|
|
606
|
+
if (w.ok) {
|
|
607
|
+
// 投递成功:给该对话打上运行 token(过户后事件依旧带它)。
|
|
608
|
+
const owner = w.clientId ? this.clients.get(w.clientId) : undefined;
|
|
609
|
+
if (owner) {
|
|
610
|
+
try {
|
|
611
|
+
const conv = w.conversationId ? owner.getConversation(w.conversationId) : undefined;
|
|
612
|
+
owner.markPluginRun(runId, conv);
|
|
613
|
+
}
|
|
614
|
+
catch {
|
|
615
|
+
/* 打标尽力而为,不影响已投递的请求 */
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return { conversationId: w.conversationId ?? target, clientId: w.clientId ?? clientId, runId };
|
|
619
|
+
}
|
|
603
620
|
}
|
|
604
621
|
// 2. 工作空间:不传回落伪客户端当前目录;传了必须存在且非系统目录。
|
|
605
622
|
const cwdReq = String(req?.cwd ?? "").trim();
|
|
@@ -636,9 +653,17 @@ export class AgentService {
|
|
|
636
653
|
throw new Error(`chatFromPlugin: 切换思考强度失败(${thinking}):${err.message}`);
|
|
637
654
|
}
|
|
638
655
|
}
|
|
639
|
-
|
|
656
|
+
// 打运行 token(没真跑起来就不认领,不会污染用户自己下一轮的事件归属)。
|
|
657
|
+
let stampedId = "";
|
|
658
|
+
try {
|
|
659
|
+
stampedId = cs.markPluginRun(runId);
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
/* 打标尽力而为 */
|
|
663
|
+
}
|
|
664
|
+
const conversationId = stampedId || (cs.readConversationForPlugins()?.conversationId ?? "");
|
|
640
665
|
void cs.prompt(text);
|
|
641
|
-
return { conversationId, clientId };
|
|
666
|
+
return { conversationId, clientId, runId };
|
|
642
667
|
}
|
|
643
668
|
/** 内置定时任务的无头执行(issue #184,server/scheduler-tasks.ts 的 executor)。
|
|
644
669
|
* 每个任务独立伪客户端 `scheduler:<taskId>`(专属会话连续、无浏览器也能跑);
|