pi-web-ui 0.99.0 → 0.101.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 +90 -1
- package/README.md +48 -45
- package/README.zh-CN.md +43 -40
- package/bin/pi-web-ui.mjs +172 -40
- package/dist/server/agent-formatters.js +191 -0
- package/dist/server/agent-service-daemon.js +1266 -0
- package/dist/server/agent-service.js +9851 -11892
- package/dist/server/approval-default-rules.js +158 -0
- package/dist/server/approval-rules.js +130 -184
- package/dist/server/ask-user-question-tool.js +94 -0
- package/dist/server/attachment-store.js +38 -1
- package/dist/server/attachments.js +55 -0
- package/dist/server/bash-tool.js +83 -0
- package/dist/server/bg-servers.js +82 -2
- package/dist/server/browser-page-tool.js +207 -0
- package/dist/server/claim-files-tool.js +4 -4
- package/dist/server/client-id-utils.js +51 -0
- package/dist/server/client-state.js +63 -1
- package/dist/server/compact-context-tool.js +10 -9
- package/dist/server/compaction-markers.js +34 -1
- package/dist/server/context-budget-runner.js +43 -0
- package/dist/server/conversation-read-tool.js +7 -8
- package/dist/server/conversation-touches.js +19 -0
- package/dist/server/dangling-tools.js +18 -5
- package/dist/server/delegate-mode.js +1 -0
- package/dist/server/delegate-task.js +10 -14
- package/dist/server/dispatch-domain-handlers.js +631 -0
- package/dist/server/dispatch-plugin-handlers.js +300 -0
- package/dist/server/dsh/dsh-agent-service.js +125 -13
- package/dist/server/edit-soft-tool.js +10 -12
- package/dist/server/eval-tool.js +4 -5
- package/dist/server/goal-evidence.js +180 -0
- package/dist/server/goal-service.js +49 -9
- package/dist/server/hashline-engine.js +199 -32
- package/dist/server/index.js +212 -944
- package/dist/server/left-panel-running.js +115 -0
- package/dist/server/load-tools-tool.js +100 -0
- package/dist/server/lsp-tool.js +50 -28
- package/dist/server/marker-service.js +53 -12
- package/dist/server/markers/builtins/action.js +108 -0
- package/dist/server/markers/index.js +4 -1
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/market-service.js +277 -0
- package/dist/server/mcp-bridge.js +137 -30
- package/dist/server/mcp-hot-reload.js +84 -27
- package/dist/server/mcp-manager.js +215 -0
- package/dist/server/message-entry-resolver.js +32 -0
- package/dist/server/orphan-manager.js +44 -0
- package/dist/server/patch-remote-catalog.js +28 -10
- package/dist/server/patch-tool.js +9 -8
- package/dist/server/persona-chain.js +63 -0
- package/dist/server/plan-mode.js +9 -6
- package/dist/server/plan-update-tool.js +96 -0
- package/dist/server/plugin-api-catalog.js +30 -3
- package/dist/server/plugin-conversation-view.js +47 -0
- package/dist/server/plugin-facilities.js +13 -3
- package/dist/server/plugin-ui-slots.js +39 -0
- package/dist/server/plugins.js +183 -63
- package/dist/server/present-files-tool.js +10 -11
- package/dist/server/preset-fields.js +700 -0
- package/dist/server/preset-share.js +1179 -0
- package/dist/server/process-utils.js +30 -0
- package/dist/server/prompt-assembler.js +80 -0
- package/dist/server/prompt-composer.js +23 -9
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/read-tool.js +8 -10
- package/dist/server/resolve-global-sdk.js +80 -18
- package/dist/server/schedule-agent-tool.js +147 -146
- package/dist/server/scm-commitmsg.js +74 -0
- package/dist/server/sdk-origin.js +125 -37
- package/dist/server/serialize.js +97 -7
- package/dist/server/session-branch.js +367 -0
- package/dist/server/session-parser.js +235 -0
- package/dist/server/session-search.js +158 -0
- package/dist/server/settings-service.js +115 -84
- package/dist/server/skill-content-filler.js +33 -0
- package/dist/server/skill-tool.js +3 -4
- package/dist/server/subagent-handoff.js +18 -0
- package/dist/server/subagent-helpers.js +88 -0
- package/dist/server/subagents.js +15 -22
- package/dist/server/terminals.js +171 -91
- package/dist/server/tool-approval.js +3 -1
- package/dist/server/tool-guards.js +527 -0
- package/dist/server/tool-host-factories.js +217 -0
- package/dist/server/tool-manager.js +84 -23
- package/dist/server/tool-prompt-overrides.js +158 -0
- package/dist/server/tool-prompts.js +42 -0
- package/dist/server/tool-signature.js +104 -0
- package/dist/server/wait-subscription-scan.js +46 -1
- package/dist/server/workspace-snapshot.js +60 -11
- package/extensions/webui.ts +90 -24
- package/package.json +5 -3
- package/plugin-sdk/README.md +25 -4
- package/plugin-sdk/import-check.mjs +210 -0
- package/plugin-sdk/index.d.ts +21 -1
- package/plugin-sdk/index.mjs +6 -0
- package/plugins/catalog.json +53 -2
- package/themes/aetheris.css +3 -1
- package/themes/translucent.css +8 -1
- package/themes/transparent.css +9 -1
- package/themes/zhupi-dark.css +1 -1
- package/themes/zhupi.css +1 -1
- package/web/dist/assets/{TerminalPanel-NerrJlTS.js → TerminalPanel-DD7I5_aC.js} +2 -2
- package/web/dist/assets/index-CpjA1YdT.css +1 -0
- package/web/dist/assets/index-nKn87VuM.js +678 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BdMaGCcs.css +0 -1
- package/web/dist/assets/index-ByCBN4Kt.js +0 -368
package/dist/server/plugins.js
CHANGED
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
* - activate 抛错只标记 error 字段并记日志,绝不影响主进程。
|
|
18
18
|
*/
|
|
19
19
|
import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
20
|
-
import { existsSync, readFileSync, renameSync, watch as fsWatch, writeFileSync } from "node:fs";
|
|
20
|
+
import { cpSync, existsSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync } from "node:fs";
|
|
21
21
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
22
22
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
23
|
+
import {} from "./protocol.js";
|
|
24
|
+
import { UI_SLOTS } from "./plugin-ui-slots.js";
|
|
25
|
+
import { LeftPanelRunningStore } from "./left-panel-running.js";
|
|
23
26
|
import { pick } from "./i18n.js";
|
|
24
27
|
import { PluginStorage, PluginSecrets, ensurePluginDeps, WorkspaceFS, withFileRmwLock } from "./plugin-facilities.js";
|
|
25
28
|
import { parseCronSpec, armDelay, nextCronFire, loadScheduleRecords, saveScheduleRecords, } from "./plugin-schedule.js";
|
|
@@ -34,12 +37,37 @@ import { AGENT_TOOL_CATALOG } from "./tool-manager.js";
|
|
|
34
37
|
import { applyPostEdit, denialText, freezeParams, isBlockingDecision, normalizePostEdit, normalizePreDecision, withGuardTimeout, } from "./plugin-tool-guard.js";
|
|
35
38
|
// 工作区根的归一化与 client-state 共用一份(同一份语义:只收绝对路径 / 去重 / 上限)。
|
|
36
39
|
import { normalizeWorkspaceRoots } from "./client-state.js";
|
|
40
|
+
import { compareVersions, ensureBackup } from "./plugin-updater.js";
|
|
37
41
|
import { createProject, isInsideRoot, realPathOfNearest, } from "./plugin-project.js";
|
|
38
42
|
import { createHash } from "node:crypto";
|
|
39
43
|
import { execFile } from "node:child_process";
|
|
40
44
|
import { promisify } from "node:util";
|
|
41
45
|
/** 合法插件 id:字母/数字/下划线/连字符,防路径穿越(同 themes.ts 的做法)。 */
|
|
42
46
|
const ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
47
|
+
/** 交给插件前的防御性拷贝:provider 回的是快照管线的**活引用** —— messages 数组与
|
|
48
|
+
* 元素对象都被 60ms 推送管线缓存复用(lastMessagesArray / uiMessageCache),插件原地
|
|
49
|
+
* 改一个字段/挪一个元素,污染的就是推给真实客户端的快照。浅拷数组 + 元素对象
|
|
50
|
+
* structuredClone;元素是纯 JSON 结构(details 已过 JSON.stringify 闸),structuredClone
|
|
51
|
+
* 不会失败,JSON 往返只是万一携带不可克隆值时的兜底。
|
|
52
|
+
* `getActiveConversation` 与 `emitClientModelChanged` 共用(两处都要发快照给插件)。 */
|
|
53
|
+
function copySnapshotForPlugins(snap) {
|
|
54
|
+
return {
|
|
55
|
+
...snap,
|
|
56
|
+
messages: snap.messages.map((m) => {
|
|
57
|
+
try {
|
|
58
|
+
return structuredClone(m);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(JSON.stringify(m));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return { ...m }; // 连 JSON 往返都失败(循环引用):至少不共享顶层对象
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
43
71
|
/** 每插件保留最近 N 条运行时日志(内存封顶,防刷爆)。 */
|
|
44
72
|
export const PLUGIN_LOG_CAP = 200;
|
|
45
73
|
/** 单条日志文本截断上限(字符)。 */
|
|
@@ -252,32 +280,7 @@ const SETTING_OPTIONS_FROM = new Set(["models", "thinkingLevels"]);
|
|
|
252
280
|
* 不认识的 slot / kind / when 直接丢弃(旧宿主读到新字段也不会崩,新宿主读到旧字段同理)。
|
|
253
281
|
* 归属由宿主决定:全局 id = `<pluginId>:<itemId>`。
|
|
254
282
|
*/
|
|
255
|
-
export
|
|
256
|
-
"topbar.primary",
|
|
257
|
-
"topbar.overflow",
|
|
258
|
-
"bottombar",
|
|
259
|
-
"composer.leading",
|
|
260
|
-
"composer.actions",
|
|
261
|
-
"message.actions",
|
|
262
|
-
"rightpanel.tabs",
|
|
263
|
-
"contextmenu.topbar",
|
|
264
|
-
"contextmenu.message",
|
|
265
|
-
"contextmenu.session",
|
|
266
|
-
"contextmenu.file",
|
|
267
|
-
"contextmenu.toolcall",
|
|
268
|
-
"settings.pages",
|
|
269
|
-
"leftpanel.sessions",
|
|
270
|
-
"chat.header",
|
|
271
|
-
"chat.empty",
|
|
272
|
-
"file.preview.toolbar",
|
|
273
|
-
"terminal.toolbar",
|
|
274
|
-
"scm.toolbar",
|
|
275
|
-
"goalbar.actions",
|
|
276
|
-
"notice.actions",
|
|
277
|
-
"modal.dialog",
|
|
278
|
-
"sidebar.left",
|
|
279
|
-
"sidebar.right",
|
|
280
|
-
]);
|
|
283
|
+
export { UI_SLOTS };
|
|
281
284
|
/** manifest 里可以写更自然的简写(作者少踩坑):解析时映射到完整 slot 名。 */
|
|
282
285
|
export const UI_SLOT_ALIASES = {
|
|
283
286
|
topbar: "topbar.primary",
|
|
@@ -861,10 +864,6 @@ function readStoredSettings(dir) {
|
|
|
861
864
|
}
|
|
862
865
|
return {};
|
|
863
866
|
}
|
|
864
|
-
function storedSettingsValues(dir, schema, secrets, overlay = {}) {
|
|
865
|
-
// 浏览器侧 secret 只看到有无(布尔),明文永不下发;无 secrets 上下文(如单测)回落 false。
|
|
866
|
-
return resolveSettingsValues(schema, readStoredSettings(dir), overlay, secrets ? { has: (k) => secrets.has(k) } : undefined).values;
|
|
867
|
-
}
|
|
868
867
|
/** 插件运行时视角的设置值:非 secret 与 storedSettingsValues 同口径;secret 返回真值
|
|
869
868
|
* (无则回落默认值/空串)。只给插件服务端代码用,绝不下发浏览器。 */
|
|
870
869
|
function runtimeSettingsValues(dir, schema, secrets, overlay = {}) {
|
|
@@ -1005,6 +1004,10 @@ export class PluginManager {
|
|
|
1005
1004
|
pluginBgTasks = new Map();
|
|
1006
1005
|
/** 任务集合变化回调(index.ts 接到 AgentService,重推 bg_servers)。 */
|
|
1007
1006
|
onBgTasksChanged = undefined;
|
|
1007
|
+
/** P3:左栏插件运行条目(见 left-panel-running.ts)。 */
|
|
1008
|
+
panelRunning = new LeftPanelRunningStore();
|
|
1009
|
+
panelPushTimer = null;
|
|
1010
|
+
panelSweepTimer = null;
|
|
1008
1011
|
/** 服务端重载纪元:每次 reload() +1,前端用作 import 缓存击穿参数。 */
|
|
1009
1012
|
epochCounter = 0;
|
|
1010
1013
|
/** 插件市场列表纪元:每次 add/remove +1,前端据此重渲。 */
|
|
@@ -1474,7 +1477,7 @@ export class PluginManager {
|
|
|
1474
1477
|
}
|
|
1475
1478
|
/** agent-service 调(P1-5):bash/read 执行前的守卫求值。首个 deny/ask 胜出;
|
|
1476
1479
|
* 守卫抛错/超时一律按弃权(不阻断)。无守卫时回 allow,调用方可直接放行。 */
|
|
1477
|
-
async evaluateToolPre(req,
|
|
1480
|
+
async evaluateToolPre(req, _lang = "en") {
|
|
1478
1481
|
const frozen = {
|
|
1479
1482
|
toolName: req.toolName,
|
|
1480
1483
|
params: freezeParams(req.params),
|
|
@@ -1554,7 +1557,8 @@ export class PluginManager {
|
|
|
1554
1557
|
guardDenialText(verdict, pluginId, lang = "en") {
|
|
1555
1558
|
return denialText(verdict, pluginId, lang);
|
|
1556
1559
|
}
|
|
1557
|
-
/** index.ts
|
|
1560
|
+
/** index.ts 注入:读取对话快照(轨迹类插件经 host.getActiveConversation 调用)。
|
|
1561
|
+
* #542:按 clientId 取「该标签页正在看的对话」;缺省回落「最近活跃的非子代理」。 */
|
|
1558
1562
|
conversationProvider = undefined;
|
|
1559
1563
|
/** index.ts 注入:插件无头调用 agent(微信通道等经 host.chat 调用)。 */
|
|
1560
1564
|
chatProvider = undefined;
|
|
@@ -1596,7 +1600,7 @@ export class PluginManager {
|
|
|
1596
1600
|
activatingGates = new Map();
|
|
1597
1601
|
/** 会话统计扇出(异常隔离;订阅者崩了只记日志)。发送方(如定期推送快照统计处)负责节流。 */
|
|
1598
1602
|
emitStats(s) {
|
|
1599
|
-
for (const h of
|
|
1603
|
+
for (const h of this.statsHandlers) {
|
|
1600
1604
|
try {
|
|
1601
1605
|
h(s);
|
|
1602
1606
|
}
|
|
@@ -1607,7 +1611,7 @@ export class PluginManager {
|
|
|
1607
1611
|
}
|
|
1608
1612
|
/** 流式增量透传(异常隔离;宿主不做节流,由发送方保证频率)。 */
|
|
1609
1613
|
emitStreaming(ev) {
|
|
1610
|
-
for (const h of
|
|
1614
|
+
for (const h of this.streamingHandlers) {
|
|
1611
1615
|
try {
|
|
1612
1616
|
h(ev);
|
|
1613
1617
|
}
|
|
@@ -1674,39 +1678,37 @@ export class PluginManager {
|
|
|
1674
1678
|
this.chatWaiters.push(entry);
|
|
1675
1679
|
});
|
|
1676
1680
|
}
|
|
1677
|
-
/** 当前打开对话的快照(无提供者/暂无对话时返回 null)。
|
|
1678
|
-
|
|
1681
|
+
/** 当前打开对话的快照(无提供者/暂无对话时返回 null)。
|
|
1682
|
+
* #542:options.clientId 取该标签页正在看的对话;缺省 = 全局回落
|
|
1683
|
+
* (最近活跃的**非子代理**会话,子代理不再把用户正在看的对话挤出去)。 */
|
|
1684
|
+
getActiveConversation(options) {
|
|
1679
1685
|
let snap;
|
|
1680
1686
|
try {
|
|
1681
|
-
snap = this.conversationProvider?.() ?? null;
|
|
1687
|
+
snap = this.conversationProvider?.(options) ?? null;
|
|
1682
1688
|
}
|
|
1683
1689
|
catch (err) {
|
|
1684
1690
|
console.error("[plugins] conversationProvider failed:", err);
|
|
1685
1691
|
return null;
|
|
1686
1692
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1693
|
+
return snap ? copySnapshotForPlugins(snap) : null;
|
|
1694
|
+
}
|
|
1695
|
+
/** agent-service 调:某客户端的对话模型切换成功(#542)—— 订阅
|
|
1696
|
+
* host.onClientModelChanged 的插件立即收到新快照(异常隔离,不会拖慢切换)。 */
|
|
1697
|
+
emitClientModelChanged(snap) {
|
|
1698
|
+
const copy = copySnapshotForPlugins(snap);
|
|
1699
|
+
for (const p of this.loaded.values()) {
|
|
1700
|
+
const hs = p.modelChangeHandlers;
|
|
1701
|
+
if (!hs || hs.size === 0)
|
|
1702
|
+
continue;
|
|
1703
|
+
for (const h of hs) {
|
|
1697
1704
|
try {
|
|
1698
|
-
|
|
1705
|
+
h(copy);
|
|
1699
1706
|
}
|
|
1700
|
-
catch {
|
|
1701
|
-
|
|
1702
|
-
return JSON.parse(JSON.stringify(m));
|
|
1703
|
-
}
|
|
1704
|
-
catch {
|
|
1705
|
-
return { ...m }; // 连 JSON 往返都失败(循环引用):至少不共享顶层对象
|
|
1706
|
-
}
|
|
1707
|
+
catch (err) {
|
|
1708
|
+
console.error(`[plugin:${p.info.id}] client-model-changed handler failed:`, err);
|
|
1707
1709
|
}
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1710
1712
|
}
|
|
1711
1713
|
/** agent-service 调:当前打开对话变了(切历史会话/切 running 对话/新对话)——
|
|
1712
1714
|
* 轨迹类插件靠它重拉时间线(异常隔离)。 */
|
|
@@ -1729,7 +1731,7 @@ export class PluginManager {
|
|
|
1729
1731
|
* run_end 顺带唤醒 host.chatWait 的等待者(按 conversationId 匹配)。 */
|
|
1730
1732
|
emitRunEvent(ev) {
|
|
1731
1733
|
if (ev.type === "run_end" && ev.conversationId) {
|
|
1732
|
-
for (const w of
|
|
1734
|
+
for (const w of this.chatWaiters) {
|
|
1733
1735
|
if (w.conversationId !== ev.conversationId)
|
|
1734
1736
|
continue;
|
|
1735
1737
|
try {
|
|
@@ -1976,6 +1978,35 @@ export class PluginManager {
|
|
|
1976
1978
|
}
|
|
1977
1979
|
}
|
|
1978
1980
|
}
|
|
1981
|
+
/** P3:节流广播左栏运行条目(同一窗口内的多次变更合并成一条,约 500ms)。 */
|
|
1982
|
+
schedulePanelPush() {
|
|
1983
|
+
if (this.panelPushTimer)
|
|
1984
|
+
return;
|
|
1985
|
+
this.panelPushTimer = setTimeout(() => {
|
|
1986
|
+
this.panelPushTimer = null;
|
|
1987
|
+
this.deliverAll({ type: "plugin_panel_items", groups: this.panelRunning.groups() });
|
|
1988
|
+
}, 500);
|
|
1989
|
+
this.panelPushTimer.unref?.();
|
|
1990
|
+
}
|
|
1991
|
+
/** P3:心跳扫描(有条目才跑,每 5 秒):过期即清空并广播;条目全无则停表。 */
|
|
1992
|
+
ensurePanelSweep() {
|
|
1993
|
+
if (this.panelSweepTimer)
|
|
1994
|
+
return;
|
|
1995
|
+
this.panelSweepTimer = setInterval(() => {
|
|
1996
|
+
const expired = this.panelRunning.sweep();
|
|
1997
|
+
if (expired.length)
|
|
1998
|
+
this.schedulePanelPush();
|
|
1999
|
+
if (this.panelRunning.size === 0 && this.panelSweepTimer) {
|
|
2000
|
+
clearInterval(this.panelSweepTimer);
|
|
2001
|
+
this.panelSweepTimer = null;
|
|
2002
|
+
}
|
|
2003
|
+
}, 5000);
|
|
2004
|
+
this.panelSweepTimer.unref?.();
|
|
2005
|
+
}
|
|
2006
|
+
/** P3:attach 时补发的全量(index.ts 用)。 */
|
|
2007
|
+
panelGroups() {
|
|
2008
|
+
return this.panelRunning.groups();
|
|
2009
|
+
}
|
|
1979
2010
|
/** 当前目录清单(重扫 manifest,不重新 import)。 */
|
|
1980
2011
|
async list(lang) {
|
|
1981
2012
|
return this.scan(lang);
|
|
@@ -2142,7 +2173,7 @@ export class PluginManager {
|
|
|
2142
2173
|
}
|
|
2143
2174
|
}
|
|
2144
2175
|
// ③ 兜底:清掉插件名下的代理前缀(该插件名下但未经栈登记的残留)。
|
|
2145
|
-
for (const prefix of
|
|
2176
|
+
for (const prefix of this.proxyRoutes.keys()) {
|
|
2146
2177
|
if (pluginIds.has(this.proxyRoutes.get(prefix).pluginId))
|
|
2147
2178
|
this.proxyRoutes.delete(prefix);
|
|
2148
2179
|
}
|
|
@@ -2154,8 +2185,64 @@ export class PluginManager {
|
|
|
2154
2185
|
this.runtimeDiags.clear();
|
|
2155
2186
|
this.pluginLogs.clear();
|
|
2156
2187
|
}
|
|
2188
|
+
/**
|
|
2189
|
+
* 检查随包内置官方插件(<pkgRoot>/plugins/)与用户数据目录(<dataDir>/plugins/)的版本。
|
|
2190
|
+
* 若用户已安装的官方插件版本落后于当前随包版本,自动备份旧版本并增量同步更新代码(保留用户数据/设置)。
|
|
2191
|
+
*/
|
|
2192
|
+
syncBuiltinPlugins() {
|
|
2193
|
+
if (!this.builtinCatalogPath || !existsSync(this.builtinCatalogPath))
|
|
2194
|
+
return;
|
|
2195
|
+
const builtinDir = dirname(this.builtinCatalogPath);
|
|
2196
|
+
if (!existsSync(builtinDir))
|
|
2197
|
+
return;
|
|
2198
|
+
let names;
|
|
2199
|
+
try {
|
|
2200
|
+
names = readdirSync(this.pluginsDir);
|
|
2201
|
+
}
|
|
2202
|
+
catch {
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
// 只有在官方 catalog.json 中登记的官方插件,才属于随宿主自动同步维护的对象(避免误覆盖测试或非 catalog 目录)
|
|
2206
|
+
let builtinCatalogIds;
|
|
2207
|
+
try {
|
|
2208
|
+
const catalogEntries = JSON.parse(readFileSync(this.builtinCatalogPath, "utf8"));
|
|
2209
|
+
builtinCatalogIds = new Set(catalogEntries.map((e) => e?.id).filter((id) => typeof id === "string"));
|
|
2210
|
+
}
|
|
2211
|
+
catch {
|
|
2212
|
+
builtinCatalogIds = new Set();
|
|
2213
|
+
}
|
|
2214
|
+
for (const name of names) {
|
|
2215
|
+
if (!ID_RE.test(name) || !builtinCatalogIds.has(name))
|
|
2216
|
+
continue;
|
|
2217
|
+
const targetDir = join(this.pluginsDir, name);
|
|
2218
|
+
const sourceDir = join(builtinDir, name);
|
|
2219
|
+
const targetManifest = join(targetDir, "manifest.json");
|
|
2220
|
+
const sourceManifest = join(sourceDir, "manifest.json");
|
|
2221
|
+
if (!existsSync(sourceDir) || !existsSync(sourceManifest) || !existsSync(targetManifest)) {
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
try {
|
|
2225
|
+
const srcRaw = JSON.parse(readFileSync(sourceManifest, "utf8"));
|
|
2226
|
+
const tgtRaw = JSON.parse(readFileSync(targetManifest, "utf8"));
|
|
2227
|
+
const srcVer = typeof srcRaw.version === "string" ? srcRaw.version.trim() : "";
|
|
2228
|
+
const tgtVer = typeof tgtRaw.version === "string" ? tgtRaw.version.trim() : "";
|
|
2229
|
+
if (srcVer && tgtVer && compareVersions(srcVer, tgtVer) > 0) {
|
|
2230
|
+
ensureBackup(this.dataDir, name, { source: `builtin:${srcVer}` });
|
|
2231
|
+
cpSync(sourceDir, targetDir, {
|
|
2232
|
+
recursive: true,
|
|
2233
|
+
filter: (s) => !/(^|[\\/])(\.git|node_modules)([\\/]|$)/.test(s),
|
|
2234
|
+
});
|
|
2235
|
+
console.log(`[plugins] 内置插件 ${name} 随宿主自动同步升级:${tgtVer} → ${srcVer}`);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
catch (err) {
|
|
2239
|
+
console.warn(`[plugins] 自动同步内置插件 ${name} 失败:`, err);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2157
2243
|
/** 读 manifest 清单;坏目录(无 manifest/id 非法)直接跳过。 */
|
|
2158
2244
|
async scan(lang) {
|
|
2245
|
+
this.syncBuiltinPlugins();
|
|
2159
2246
|
const l = lang?.() ?? "en";
|
|
2160
2247
|
let names;
|
|
2161
2248
|
try {
|
|
@@ -2426,7 +2513,7 @@ export class PluginManager {
|
|
|
2426
2513
|
const hit = [];
|
|
2427
2514
|
for (;;) {
|
|
2428
2515
|
let changed = false;
|
|
2429
|
-
for (const [id, p] of
|
|
2516
|
+
for (const [id, p] of this.loaded) {
|
|
2430
2517
|
if (p.info.error)
|
|
2431
2518
|
continue;
|
|
2432
2519
|
const req = byId.get(id)?.requires ?? p.info.requires;
|
|
@@ -2505,10 +2592,12 @@ export class PluginManager {
|
|
|
2505
2592
|
const postGuards = new Set();
|
|
2506
2593
|
const runHandlers = new Set();
|
|
2507
2594
|
const convChangeHandlers = new Set();
|
|
2595
|
+
const modelChangeHandlers = new Set();
|
|
2508
2596
|
const attachHandlers = new Set();
|
|
2509
2597
|
const cwdHandlers = new Set();
|
|
2510
2598
|
const httpRoutes = new Map();
|
|
2511
2599
|
const bgTaskTable = new Map();
|
|
2600
|
+
let leftPanelOwned = false;
|
|
2512
2601
|
const settingsHandlers = new Set();
|
|
2513
2602
|
// 可逆副作用栈:本插件的全部注册面(工具/命令/路由/代理/watch/定时/后台任务/
|
|
2514
2603
|
// UI 条目/事件订阅…)都经 effects.add 登记,反激活时**逆序**回卷 —— 插件忘写
|
|
@@ -2848,7 +2937,11 @@ export class PluginManager {
|
|
|
2848
2937
|
convChangeHandlers.add(h);
|
|
2849
2938
|
return () => convChangeHandlers.delete(h);
|
|
2850
2939
|
},
|
|
2851
|
-
|
|
2940
|
+
onClientModelChanged: (h) => {
|
|
2941
|
+
modelChangeHandlers.add(h);
|
|
2942
|
+
return () => modelChangeHandlers.delete(h);
|
|
2943
|
+
},
|
|
2944
|
+
getActiveConversation: (opts) => self.getActiveConversation(opts),
|
|
2852
2945
|
chat: (req) => sendChat(req),
|
|
2853
2946
|
chatWait: async (req, opts) => {
|
|
2854
2947
|
try {
|
|
@@ -3191,6 +3284,32 @@ export class PluginManager {
|
|
|
3191
3284
|
return createProject(spec, { onProgress: (line) => self.notifyAll("info", line) });
|
|
3192
3285
|
},
|
|
3193
3286
|
},
|
|
3287
|
+
leftPanel: {
|
|
3288
|
+
setRunning: (items, opts) => {
|
|
3289
|
+
if (!can("ui"))
|
|
3290
|
+
return;
|
|
3291
|
+
if (!leftPanelOwned) {
|
|
3292
|
+
leftPanelOwned = true;
|
|
3293
|
+
effects.add("leftPanel", () => {
|
|
3294
|
+
leftPanelOwned = false;
|
|
3295
|
+
if (self.panelRunning.clear(info.id))
|
|
3296
|
+
self.schedulePanelPush();
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
const outcome = self.panelRunning.set(info.id, info.name || info.id, items, opts);
|
|
3300
|
+
for (const d of outcome.diags)
|
|
3301
|
+
self.pushRuntimeDiag(info.id, d);
|
|
3302
|
+
if (outcome.changed)
|
|
3303
|
+
self.schedulePanelPush();
|
|
3304
|
+
self.ensurePanelSweep();
|
|
3305
|
+
},
|
|
3306
|
+
clear: () => {
|
|
3307
|
+
if (!can("ui"))
|
|
3308
|
+
return;
|
|
3309
|
+
if (self.panelRunning.clear(info.id))
|
|
3310
|
+
self.schedulePanelPush();
|
|
3311
|
+
},
|
|
3312
|
+
},
|
|
3194
3313
|
registerBackgroundTask: (task) => {
|
|
3195
3314
|
const id = String(task?.id ?? "").trim();
|
|
3196
3315
|
if (!id || bgTaskTable.has(id)) {
|
|
@@ -3685,7 +3804,7 @@ export class PluginManager {
|
|
|
3685
3804
|
const handlers = self.busHandlers.get(t);
|
|
3686
3805
|
if (!handlers)
|
|
3687
3806
|
return;
|
|
3688
|
-
for (const h of
|
|
3807
|
+
for (const h of handlers) {
|
|
3689
3808
|
try {
|
|
3690
3809
|
h(ev);
|
|
3691
3810
|
}
|
|
@@ -3752,6 +3871,7 @@ export class PluginManager {
|
|
|
3752
3871
|
postGuards,
|
|
3753
3872
|
runHandlers,
|
|
3754
3873
|
convChangeHandlers,
|
|
3874
|
+
modelChangeHandlers,
|
|
3755
3875
|
attachHandlers,
|
|
3756
3876
|
cwdHandlers,
|
|
3757
3877
|
effects,
|
|
@@ -239,27 +239,26 @@ export function makePresentFilesTool(fallbackCwd, options = {}) {
|
|
|
239
239
|
return defineTool({
|
|
240
240
|
name: PRESENT_FILES_TOOL_NAME,
|
|
241
241
|
label: "Show files to the user",
|
|
242
|
-
description: "Show files to the user as preview cards in the chat: images/videos/audio inline, text/markdown/HTML in a preview dialog;
|
|
243
|
-
"
|
|
244
|
-
"Give workspace-relative paths (max 12
|
|
245
|
-
|
|
246
|
-
promptSnippet: "show images/videos/text files to the user as preview cards",
|
|
242
|
+
description: "Show files to the user as preview cards in the chat: images/videos/audio inline, text/markdown/HTML in a preview dialog; " +
|
|
243
|
+
"each card can open locally, reveal in file manager, download, or copy path. " +
|
|
244
|
+
"Give workspace-relative paths (max 12); `title`/`note` show above the cards, `caption` next to the name, `focus: true` opens that item immediately.",
|
|
245
|
+
promptSnippet: "show a produced artifact (image/chart/report) to the user",
|
|
247
246
|
promptGuidelines: [
|
|
248
|
-
"After producing something visual or user-facing (screenshot, chart, video, report, log, build output),
|
|
249
|
-
"
|
|
247
|
+
"After producing something visual or user-facing (screenshot, chart, video, report, log, build output), show it with present_files instead of only printing the path",
|
|
248
|
+
"Skip it for ordinary source edits the user did not ask to see; never call it twice for the same file in one turn",
|
|
250
249
|
],
|
|
251
250
|
parameters: Type.Object({
|
|
252
251
|
title: Type.Optional(Type.String({
|
|
253
|
-
description: "Optional card title
|
|
252
|
+
description: "Optional card title (short, e.g. 'Q3 revenue chart').",
|
|
254
253
|
})),
|
|
255
254
|
note: Type.Optional(Type.String({
|
|
256
|
-
description: "Optional one-line note above the cards (markdown
|
|
255
|
+
description: "Optional one-line note above the cards (markdown).",
|
|
257
256
|
})),
|
|
258
257
|
items: Type.Array(Type.Object({
|
|
259
258
|
path: Type.String({ description: "File path (workspace-relative like 'docs/chart.png', or absolute)." }),
|
|
260
|
-
caption: Type.Optional(Type.String({ description: "Optional short caption
|
|
259
|
+
caption: Type.Optional(Type.String({ description: "Optional short caption next to the file name." })),
|
|
261
260
|
focus: Type.Optional(Type.Boolean({
|
|
262
|
-
description: "true →
|
|
261
|
+
description: "true → open this item in the preview dialog immediately.",
|
|
263
262
|
})),
|
|
264
263
|
}), { description: `Files to show (1-${MAX_PRESENT_ITEMS}).` }),
|
|
265
264
|
}),
|