pi-web-ui 0.108.0 → 0.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +21 -1
  3. package/README.zh-CN.md +21 -1
  4. package/README.zh-TW.md +201 -677
  5. package/dist/server/agent-service-daemon.js +2 -2
  6. package/dist/server/agent-service.js +47 -36
  7. package/dist/server/attachments.js +26 -6
  8. package/dist/server/client-state.js +4 -3
  9. package/dist/server/dispatch-domain-handlers.js +2 -0
  10. package/dist/server/dispatch-plugin-handlers.js +1 -0
  11. package/dist/server/dsh/dsh-agent-service.js +2 -2
  12. package/dist/server/durable/durable-driver.js +1 -1
  13. package/dist/server/durable/durable-tools.js +4 -1
  14. package/dist/server/files-service.js +23 -4
  15. package/dist/server/goal-service.js +12 -3
  16. package/dist/server/index.js +39 -10
  17. package/dist/server/locales.js +33 -0
  18. package/dist/server/marker-service.js +7 -13
  19. package/dist/server/markers/builtins/action.js +5 -6
  20. package/dist/server/markers/builtins/notify.js +2 -2
  21. package/dist/server/markers/builtins/rename.js +2 -2
  22. package/dist/server/markers/registry.js +5 -1
  23. package/dist/server/message-window.js +190 -0
  24. package/dist/server/model-admin.js +0 -4
  25. package/dist/server/plugin-catalog-sync.js +10 -2
  26. package/dist/server/plugin-catalog.js +63 -10
  27. package/dist/server/plugins.js +47 -6
  28. package/dist/server/preset-share.js +2 -3
  29. package/dist/server/process-utils.js +58 -24
  30. package/dist/server/protocol-version.js +1 -1
  31. package/dist/server/settings-service.js +8 -3
  32. package/dist/server/slash-commands.js +16 -4
  33. package/dist/server/text-sniff.js +10 -7
  34. package/dist/server/themes.js +36 -1
  35. package/dist/server/universal/drivers/dsh-driver.js +1 -1
  36. package/dist/server/universal/universal-session.js +12 -4
  37. package/dist/server/worktree-service.js +1 -1
  38. package/package.json +7 -2
  39. package/plugin-sdk/index.d.ts +20 -0
  40. package/plugin-sdk/index.mjs +14 -0
  41. package/plugins/catalog.json +22 -2
  42. package/themes/aetheris.css +155 -121
  43. package/themes/ayu-light.css +19 -15
  44. package/themes/bases/flow-base.css +1363 -0
  45. package/themes/bases/obsidian-base.css +679 -0
  46. package/themes/bases/zhujian-base.css +687 -0
  47. package/themes/bases/zhupi-base.css +659 -0
  48. package/themes/catppuccin-latte.css +17 -15
  49. package/themes/catppuccin.css +5 -2
  50. package/themes/claude-code-dark.css +2 -0
  51. package/themes/codex.css +16 -14
  52. package/themes/cyberpunk.css +4 -1
  53. package/themes/dark-teal.css +4 -1
  54. package/themes/dazzle.css +3 -0
  55. package/themes/everforest-light.css +17 -15
  56. package/themes/flow-light.css +10 -931
  57. package/themes/flow.css +13 -946
  58. package/themes/geist.css +16 -14
  59. package/themes/gruvbox-light.css +13 -11
  60. package/themes/kanagawa-lotus.css +16 -14
  61. package/themes/mist.css +18 -16
  62. package/themes/nord.css +16 -12
  63. package/themes/one-dark.css +9 -5
  64. package/themes/paper.css +9 -7
  65. package/themes/rose-pine-dawn.css +14 -12
  66. package/themes/sakura.css +15 -13
  67. package/themes/solarized-light.css +19 -17
  68. package/themes/tokyo-night.css +4 -2
  69. package/themes/vs-code-dark.css +4 -3
  70. package/themes/wallpaper-flow.css +73 -1031
  71. package/themes/wallpaper-obsidian.css +4 -673
  72. package/themes/white.css +8 -6
  73. package/themes/zhujian-dark.css +6 -608
  74. package/themes/zhujian.css +6 -657
  75. package/themes/zhupi-dark.css +6 -579
  76. package/themes/zhupi.css +6 -629
  77. package/web/dist/assets/{TerminalPanel-CslRhcS7.js → TerminalPanel-BHjM6pzY.js} +1 -1
  78. package/web/dist/assets/index-DwInT7-a.css +1 -0
  79. package/web/dist/assets/index-GfVFIgIL.js +693 -0
  80. package/web/dist/index.html +2 -2
  81. package/web/dist/sw.js +1 -1
  82. package/web/dist/assets/index-C_2Fl6f6.js +0 -690
  83. package/web/dist/assets/index-D0BtO5dn.css +0 -1
@@ -43,21 +43,15 @@ export class MarkerService {
43
43
  if (!this.settings.markersEnabled)
44
44
  return "";
45
45
  const disabled = new Set(this.settings.disabledMarkers);
46
- const lines = collectGuidance(disabled, this.lang());
46
+ // AI guidance is strictly in concise English matching tool prompt guidelines.
47
+ const lines = collectGuidance(disabled, "en");
47
48
  if (lines.length === 0)
48
49
  return "";
49
- // The dynamic lines ride the `{lines}` slot so translator packs can
50
- // place them (a static table value could never inline them).
51
50
  const linesText = lines.join("\n");
52
- return pick(this.lang(), "\n\n────────── 内联标记工具(重要)──────────\n" +
53
- "状态类操作(操作建议、对话重命名、通知)请直接写在回答正文里,采用内联标记语法,而不要调用对应工具。\n" +
54
- "插件会替你执行并把标记从展示文本中移除,不会中断你的回答。\n\n" +
51
+ return ("\n\n────────── Inline Markers ──────────\n" +
52
+ "Use inline markers in reply text for status actions (never call tools for them). Markers are executed and stripped before display.\n\n" +
55
53
  linesText +
56
- "\n──────────\n", "\n\n────────── Inline marker tools (important) ──────────\n" +
57
- "Write status operations (action suggestions, conversation renaming, notifications) directly in your reply text using inline marker syntax — do not call a tool for them.\n" +
58
- "The plugin executes them and strips the markers from the displayed text without interrupting your reply.\n\n" +
59
- linesText +
60
- "\n──────────\n", "markers.service.guidance.frame", { lines: linesText });
54
+ "\n──────────\n");
61
55
  }
62
56
  setEnabled(enabled) {
63
57
  this.settings.markersEnabled = !!enabled;
@@ -237,7 +231,7 @@ export class MarkerService {
237
231
  overlayLines(conversationId) {
238
232
  const lines = [];
239
233
  for (const m of allMarkers()) {
240
- if (m.name === "suggest")
234
+ if (m.isAlias || m.name === "suggest")
241
235
  continue;
242
236
  if (this.settings.disabledMarkers.includes(m.name))
243
237
  continue;
@@ -293,7 +287,7 @@ export class MarkerService {
293
287
  const seen = new Set();
294
288
  const out = [];
295
289
  for (const m of allMarkers()) {
296
- if (m.name === "suggest")
290
+ if (m.isAlias || m.name === "suggest")
297
291
  continue;
298
292
  if (seen.has(m.name))
299
293
  continue;
@@ -17,14 +17,10 @@ export function initActionState() {
17
17
  return { actions: [], nextId: 1 };
18
18
  }
19
19
  const ACTION_GUIDANCE_ZH = [
20
- "- 建议后续操作:[[action:suggest:<文字>]](当期待用户操作时,如是否继续、后续步骤选择;在对话最底部生成按钮,用户点击即发送该文字)",
21
- "- 可指定不同按钮显示与发送内容:[[action:suggest:<按钮显示>,prompt=<实际发送文本>]]",
22
- "- 清空候选操作:[[action:clear:all]]",
20
+ "- 建议操作按钮:[[action:suggest:<按钮文字>]](一个标记对应一个按钮;多个选项请输出多个独立标记:[[action:suggest:选项A]] [[action:suggest:选项B]],切勿合并)。区分发送内容:[[action:suggest:<显示>,prompt=<发送>]]。清空:[[action:clear:all]]。",
23
21
  ];
24
22
  const ACTION_GUIDANCE_EN = [
25
- "- Suggest next actions: [[action:suggest:<text>]] (when expecting user input, e.g. whether to continue, what to do next; creates buttons at the bottom of the conversation, clicked to send text immediately)",
26
- "- Optional separate prompt: [[action:suggest:<label>,prompt=<text to send>]]",
27
- "- Clear suggestions: [[action:clear:all]]",
23
+ "- Suggest action buttons: [[action:suggest:<label>]] (one marker per button; for multiple choices output separate markers: [[action:suggest:A]] [[action:suggest:B]], NEVER join options in one marker). Separate prompt: [[action:suggest:<label>,prompt=<text>]]. Clear: [[action:clear:all]].",
28
24
  ];
29
25
  /** 语言感知的 action guidance:en 用英译、zh 用中文,默认英文。 */
30
26
  export function getActionGuidance(lang = "en") {
@@ -105,4 +101,7 @@ export const actionMarker = {
105
101
  export const suggestMarker = {
106
102
  ...actionMarker,
107
103
  name: "suggest",
104
+ isAlias: true,
105
+ guidance: [],
106
+ getGuidance: () => [],
108
107
  };
@@ -5,10 +5,10 @@ import { getServerBlock, pick } from "../../i18n.js";
5
5
  const NOTIFY_GUIDANCE_ZH = [
6
6
  // #499:guidance 只能承诺协议真实支持的级别——success 从未存在于 notice 协议
7
7
  // (protocol.ts 仅 info|warning|error),按指引用 success 会被静默降级成 info。
8
- "- [[notify:<级别>:<内容>]] 仅向用户显示一个非打断性提醒,不会进入正文。级别为 info|warning|error。",
8
+ "- 浮动通知:[[notify:<级别>:<内容>]](级别:info|warning|error,不进入正文)。",
9
9
  ];
10
10
  const NOTIFY_GUIDANCE_EN = [
11
- "- [[notify:<level>:<message>]] shows a non-interruptive notice to the user only; it never enters the reply text. Levels: info|warning|error.",
11
+ "- Non-interruptive toast: [[notify:<level>:<message>]] (level: info|warning|error; omitted from reply).",
12
12
  ];
13
13
  /** 语言感知的 notify guidance(issue #91):en 用英译、zh 用中文,默认英文。 */
14
14
  export function getNotifyGuidance(lang = "en") {
@@ -18,9 +18,9 @@ function extractTitle(token) {
18
18
  return `${fromArgs} ${fromKw}`.trim();
19
19
  return fromArgs || fromKw;
20
20
  }
21
- const RENAME_GUIDANCE_ZH = ["- 重命名当前对话:[[conv:rename:<新标题>]](在了解了用户需求后尽早重命名对话)"];
21
+ const RENAME_GUIDANCE_ZH = ["- 重命名对话:[[conv:rename:<新标题>]](明确意图后尽早调用一次)。"];
22
22
  const RENAME_GUIDANCE_EN = [
23
- "- Rename the current conversation: [[conv:rename:<new title>]] (do it early, once you understand what the user needs)",
23
+ "- Rename conversation: [[conv:rename:<title>]] (call once early when user intent is clear).",
24
24
  ];
25
25
  /** 语言感知的 conv guidance(issue #91):en 用英译、zh 用中文,默认英文。 */
26
26
  export function getRenameGuidance(lang = "en") {
@@ -14,9 +14,13 @@ export function allMarkers() {
14
14
  export function collectGuidance(disabled = new Set(), lang = "en") {
15
15
  const out = [];
16
16
  for (const m of allMarkers()) {
17
+ if (m.isAlias)
18
+ continue;
17
19
  if (disabled.has(m.name))
18
20
  continue;
19
- out.push(...(m.getGuidance?.(lang) ?? m.guidance));
21
+ const lines = m.getGuidance?.(lang) ?? m.guidance;
22
+ if (lines && lines.length > 0)
23
+ out.push(...lines);
20
24
  }
21
25
  return out;
22
26
  }
@@ -0,0 +1,190 @@
1
+ /** 尾部窗口条数(缺省 300 条)。 */
2
+ export const DEFAULT_HISTORY_WINDOW = 300;
3
+ /** 尾部窗口字符预算(缺省 150 万字符 ≈ 3MB JSON)。
4
+ *
5
+ * 只按条数裁不够用:一条巨型 tool 输出就能把几十条普通消息顶下去——实测一份
6
+ * 287 条、17MB 的转录序列化后仍有 4MB,按条数(300)根本裁不动。所以从尾部
7
+ * 往前累加**字符长度**(只读每个字符串的 `.length`,O(block 数),不展开内容),超预算即停。
8
+ */
9
+ export const DEFAULT_HISTORY_CHARS = 1_500_000;
10
+ /** 「加载更早」单页条数。 */
11
+ export const DEFAULT_HISTORY_PAGE = 30;
12
+ /** 单次翻页上限,防止一条消息把几千条历史一次拉下来。 */
13
+ const MAX_PAGE = 2000;
14
+ /** 最多为几个对话保留全量缓存(LRU)—— 引用的是引擎已序列化好的对象,只有指针开销。 */
15
+ const MAX_CACHED_CONVERSATIONS = 4;
16
+ const OFF_CONFIG = { windowSize: 0, charBudget: 0, pageSize: DEFAULT_HISTORY_PAGE };
17
+ const DEFAULT_CONFIG = {
18
+ windowSize: DEFAULT_HISTORY_WINDOW,
19
+ charBudget: DEFAULT_HISTORY_CHARS,
20
+ pageSize: DEFAULT_HISTORY_PAGE,
21
+ };
22
+ /** 从环境变量读窗口配置:`PI_WEB_HISTORY_WINDOW`(条数;0/off/false/no = 关闭)。 */
23
+ export function readMessageWindowConfig(env) {
24
+ const raw = (env.PI_WEB_HISTORY_WINDOW ?? "").trim().toLowerCase();
25
+ if (raw === "0" || raw === "off" || raw === "false" || raw === "no")
26
+ return OFF_CONFIG;
27
+ if (raw === "")
28
+ return DEFAULT_CONFIG;
29
+ const n = Number(raw);
30
+ if (!Number.isFinite(n) || n <= 0)
31
+ return DEFAULT_CONFIG;
32
+ return { ...DEFAULT_CONFIG, windowSize: Math.floor(n) };
33
+ }
34
+ /**
35
+ * 本轮窗口起点(纯函数,便于单测)。
36
+ *
37
+ * `prevStart` 是上一次下发的起点(新对话传 -1)。起点只允许**单调不增**:
38
+ * 客户端可能已经往前翻过几页,若某次全量快照把起点推回去(比如先 200 后 400),
39
+ * 客户端会凭空丢掉已经看过的历史。消息总数变少(压缩重写)时以尾部窗口为准。
40
+ */
41
+ export function computeWindowStart(prevStart, total, windowSize) {
42
+ if (windowSize <= 0)
43
+ return 0;
44
+ const tail = Math.max(0, total - windowSize);
45
+ if (prevStart < 0)
46
+ return tail;
47
+ return Math.min(prevStart, tail);
48
+ }
49
+ /** 单条消息的字符量估算:只累加各文本字段的 `.length`(每条 O(block 数),不展开内容)。 */
50
+ export function estimateMessageChars(m) {
51
+ let n = 0;
52
+ const content = m.content;
53
+ if (Array.isArray(content)) {
54
+ for (const b of content) {
55
+ // dataUrl:截图类 toolResult 是真正的重量级(实测一份长会话的 4MB JSON 里
56
+ // 3.4MB 全来自三张整页截图),漏掉它字符预算就形同虚设。
57
+ for (const k of ["text", "thinking", "argumentsText", "output", "command", "dataUrl", "summary"]) {
58
+ const v = b[k];
59
+ if (typeof v === "string")
60
+ n += v.length;
61
+ }
62
+ }
63
+ }
64
+ const summary = m.summary;
65
+ if (typeof summary === "string")
66
+ n += summary.length;
67
+ return n;
68
+ }
69
+ /**
70
+ * 首次计算窗口起点:条数上限与字符预算取**更严**的那个,且至少保留最后一条消息。
71
+ * `windowSize <= 0` 时返回 0(窗口化关闭)。
72
+ */
73
+ export function pickWindowStart(messages, cfg) {
74
+ const total = messages.length;
75
+ if (cfg.windowSize <= 0)
76
+ return 0;
77
+ const byCount = Math.max(0, total - cfg.windowSize);
78
+ if (cfg.charBudget <= 0)
79
+ return byCount;
80
+ let chars = 0;
81
+ let i = total - 1;
82
+ for (; i >= byCount; i--) {
83
+ chars += estimateMessageChars(messages[i]);
84
+ if (chars > cfg.charBudget)
85
+ return Math.min(total - 1, i + 1);
86
+ }
87
+ return byCount;
88
+ }
89
+ /**
90
+ * 连接级历史窗口。每个 socket(= 每个标签页)一份,`accept()` 包在 send 之前,
91
+ * `loadEarlier()` 由 WS 分发层直接调用。
92
+ */
93
+ export class MessageWindowTap {
94
+ send;
95
+ cfg;
96
+ convs = new Map();
97
+ /** 最近一次快照所属的对话 —— `load_earlier_messages` 不带 id,按「当前对话」服务。 */
98
+ lastConversationId = "";
99
+ constructor(send, cfg) {
100
+ this.send = send;
101
+ this.cfg = cfg;
102
+ }
103
+ get enabled() {
104
+ return this.cfg.windowSize > 0;
105
+ }
106
+ /** 引擎消息入口:窗口化 snapshot/delta,其余原样透传。 */
107
+ accept(msg) {
108
+ if (!this.enabled) {
109
+ this.send(msg);
110
+ return;
111
+ }
112
+ if (msg.type === "snapshot") {
113
+ const state = msg.state;
114
+ const full = state.messages;
115
+ const entry = this.entry(state.conversationId);
116
+ entry.full = full;
117
+ // 首次按「条数 + 字符预算」算;之后只允许单调不增(已翻过的页不能被全量快照推回去)。
118
+ entry.start =
119
+ entry.start < 0
120
+ ? pickWindowStart(full, this.cfg)
121
+ : computeWindowStart(entry.start, full.length, this.cfg.windowSize);
122
+ this.lastConversationId = state.conversationId;
123
+ this.send({
124
+ ...msg,
125
+ state: {
126
+ ...state,
127
+ messages: entry.start > 0 ? full.slice(entry.start) : full,
128
+ historyStart: entry.start,
129
+ historyTotal: full.length,
130
+ },
131
+ });
132
+ return;
133
+ }
134
+ if (msg.type === "snapshot_delta") {
135
+ const entry = this.convs.get(msg.conversationId);
136
+ if (!entry) {
137
+ // 没见过完整基线(重连后先来增量):原样透传,客户端会凭 rev 缺口自愈。
138
+ this.send(msg);
139
+ return;
140
+ }
141
+ if (msg.appended.length > 0) {
142
+ entry.full = entry.full.concat(msg.appended);
143
+ }
144
+ this.lastConversationId = msg.conversationId;
145
+ this.send({
146
+ ...msg,
147
+ state: { ...msg.state, historyStart: entry.start, historyTotal: entry.full.length },
148
+ });
149
+ return;
150
+ }
151
+ this.send(msg);
152
+ }
153
+ /** 客户端往上翻页:把窗口起点往前扩 `count` 条(`all` = 一路拉到最早)。 */
154
+ loadEarlier(count, all) {
155
+ const convId = this.lastConversationId;
156
+ const entry = convId ? this.convs.get(convId) : undefined;
157
+ if (!entry || !convId)
158
+ return;
159
+ const total = entry.full.length;
160
+ const page = all ? entry.start : Math.min(MAX_PAGE, Math.max(1, Math.floor(count ?? this.cfg.pageSize) || 1));
161
+ const start = all ? 0 : Math.max(0, entry.start - page);
162
+ const messages = start < entry.start ? entry.full.slice(start, entry.start) : [];
163
+ entry.start = start;
164
+ this.send({
165
+ type: "earlier_messages",
166
+ conversationId: convId,
167
+ messages,
168
+ historyStart: start,
169
+ historyTotal: total,
170
+ });
171
+ }
172
+ /** 取(或建)对话窗口;LRU 超限时淘汰最久未用的那个。 */
173
+ entry(convId) {
174
+ const hit = this.convs.get(convId);
175
+ if (hit) {
176
+ this.convs.delete(convId);
177
+ this.convs.set(convId, hit);
178
+ return hit;
179
+ }
180
+ const created = { full: [], start: -1 };
181
+ this.convs.set(convId, created);
182
+ while (this.convs.size > MAX_CACHED_CONVERSATIONS) {
183
+ const oldest = this.convs.keys().next();
184
+ if (oldest.done)
185
+ break;
186
+ this.convs.delete(oldest.value);
187
+ }
188
+ return created;
189
+ }
190
+ }
@@ -66,10 +66,6 @@ export function graduateOverlayModels(providers, official) {
66
66
  }
67
67
  return graduated;
68
68
  }
69
- /** 原子写 JSON(tmp + rename):进程崩溃不留半截文件。 */
70
- function atomicWriteJson(path, data) {
71
- writeJsonAtomicSync(path, data);
72
- }
73
69
  /** 原子写凭据 JSON 并修权限 0600(port from fork 50e723f,保留上游原子写语义)。
74
70
  * chmod 覆盖已存在文件(mode 选项只对新建有效)。Windows 下尽力而为。 */
75
71
  function atomicWriteCredentialJson(path, data) {
@@ -19,7 +19,7 @@
19
19
  import { existsSync, readFileSync } from "node:fs";
20
20
  import { join } from "node:path";
21
21
  import { pick } from "./i18n.js";
22
- import { normalizeSyncPayload, writeCustomCatalog } from "./plugin-catalog.js";
22
+ import { normalizeSyncPayload, writeCustomCatalog, writeCommunityCatalog } from "./plugin-catalog.js";
23
23
  import { workspacePath } from "./files-service.js";
24
24
  /**
25
25
  * 读同步文档:`http(s)://` 走网络,其余当本地文件路径 —— **只允许工作区内的路径**
@@ -110,7 +110,15 @@ export async function syncPluginCatalog(source, opts, deps) {
110
110
  if ("error" in payload)
111
111
  return { ok: false, error: payload.error };
112
112
  // 到这里才动磁盘:校验失败的文档绝不覆盖一份有效目录。
113
- writeCustomCatalog(deps.customCatalogPath, payload.entries, opts.replace === true);
113
+ const isCommunity = opts.target === "community" ||
114
+ (Boolean(deps.communityCatalogPath) &&
115
+ (source.includes("pi-web-ui-plugins/catalog.json") || source.endsWith("/community-catalog.json")));
116
+ if (isCommunity && deps.communityCatalogPath) {
117
+ writeCommunityCatalog(deps.communityCatalogPath, payload.entries);
118
+ }
119
+ else {
120
+ writeCustomCatalog(deps.customCatalogPath, payload.entries, opts.replace === true);
121
+ }
114
122
  await deps.afterWrite();
115
123
  let installed;
116
124
  if (opts.install === true && payload.entries.length) {
@@ -64,7 +64,9 @@ function atomicWrite(path, data) {
64
64
  writeJsonAtomicSync(path, data);
65
65
  }
66
66
  /** 把任意对象规范化为合法条目;非法则返回 null。 */
67
- function toEntry(raw, builtin) {
67
+ function toEntry(raw, originOrBuiltin) {
68
+ const origin = typeof originOrBuiltin === "boolean" ? (originOrBuiltin ? "builtin" : "custom") : originOrBuiltin;
69
+ const builtin = origin === "builtin";
68
70
  const source = typeof raw.source === "string" ? raw.source.trim() : "";
69
71
  if (!isValidSource(source))
70
72
  return null;
@@ -83,6 +85,7 @@ function toEntry(raw, builtin) {
83
85
  name,
84
86
  source,
85
87
  builtin,
88
+ origin,
86
89
  ...(nameEn ? { nameEn } : {}),
87
90
  ...(description ? { description } : {}),
88
91
  ...(descriptionEn ? { descriptionEn } : {}),
@@ -91,38 +94,70 @@ function toEntry(raw, builtin) {
91
94
  ...(homepage ? { homepage } : {}),
92
95
  };
93
96
  }
94
- /** 读合并后的目录:builtin 在前,custom 在后(同 id 时 custom 覆盖 builtin)。
97
+ /** 读合并后的目录:
98
+ * 1. builtin : 项目随包内置核心插件(不可移除);
99
+ * 2. community : 官方社区生态清单(pi-web-ui-plugins 自动化审核构建,不可移除);
100
+ * 3. custom : 用户在设置面板手动填写的自定义条目(同 id 可覆盖 builtin/community,支持单独移除)。
95
101
  * custom 覆盖 builtin 时强制打 `overridesBuiltin: true` 标记(builtin 同时为
96
- * false):显示字段(name/icon/description)来自用户可写来源,可能仿冒官方条目,
97
- * 前端据此把它标识为「自定义覆盖」。source 始终保留真实(custom)安装来源,
98
- * 不允许伪装成官方来源。 */
99
- export function readCatalog(builtinPath, customPath) {
102
+ * false):显示字段来自用户可写来源,前端据此把它标识为「自定义覆盖」。 */
103
+ export function readCatalog(builtinPath, customPath, communityPath) {
100
104
  const out = [];
105
+ const seenBuiltin = new Set();
101
106
  const seen = new Set();
107
+ // 1. 内置核心插件
102
108
  if (existsSync(builtinPath)) {
103
109
  const raw = readJsonSafe(builtinPath, []);
104
110
  if (Array.isArray(raw)) {
105
111
  for (const it of raw) {
106
- const e = it && typeof it === "object" ? toEntry(it, true) : null;
112
+ const e = it && typeof it === "object" ? toEntry(it, "builtin") : null;
107
113
  if (e && !seen.has(e.id)) {
114
+ seenBuiltin.add(e.id);
108
115
  seen.add(e.id);
109
116
  out.push(e);
110
117
  }
111
118
  }
112
119
  }
113
120
  }
121
+ // 2. 官方社区生态插件(若存在)
122
+ if (communityPath && existsSync(communityPath)) {
123
+ const rawCommunity = readJsonSafe(communityPath, []);
124
+ const list = Array.isArray(rawCommunity)
125
+ ? rawCommunity
126
+ : rawCommunity &&
127
+ typeof rawCommunity === "object" &&
128
+ Array.isArray(rawCommunity.entries)
129
+ ? rawCommunity.entries
130
+ : [];
131
+ for (const it of list) {
132
+ const e = it && typeof it === "object" ? toEntry(it, "community") : null;
133
+ if (!e)
134
+ continue;
135
+ // 内置插件绝对优先,不被社区同名条目替换
136
+ if (seenBuiltin.has(e.id))
137
+ continue;
138
+ const idx = out.findIndex((x) => x.id === e.id);
139
+ if (idx >= 0) {
140
+ out[idx] = e;
141
+ }
142
+ else {
143
+ out.push(e);
144
+ }
145
+ seen.add(e.id);
146
+ }
147
+ }
148
+ // 3. 用户在设置面板手动添加的自定义条目
114
149
  const rawCustom = readJsonSafe(customPath, {});
115
150
  const list = rawCustom && typeof rawCustom === "object" && Array.isArray(rawCustom.entries)
116
151
  ? rawCustom.entries
117
152
  : [];
118
153
  for (const it of list) {
119
- const e = it && typeof it === "object" ? toEntry(it, false) : null;
154
+ const e = it && typeof it === "object" ? toEntry(it, "custom") : null;
120
155
  if (!e)
121
156
  continue;
122
157
  const idx = out.findIndex((x) => x.id === e.id);
123
158
  if (idx >= 0) {
124
- // 覆盖了同名 builtin 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
125
- out[idx] = { ...e, builtin: false, overridesBuiltin: true };
159
+ // 覆盖了同名 builtin/community 条目:强制带标识(不信任 custom 文件里的任何自标字段)。
160
+ out[idx] = { ...e, builtin: false, origin: "custom", overridesBuiltin: seenBuiltin.has(e.id) };
126
161
  }
127
162
  else {
128
163
  out.push(e);
@@ -240,3 +275,21 @@ export function writeCustomCatalog(customPath, incoming, replace) {
240
275
  atomicWrite(customPath, { entries });
241
276
  return entries.length;
242
277
  }
278
+ /**
279
+ * 原子写入官方社区生态清单(由远端构建的 catalog.json 同步而来,全量替换)。
280
+ */
281
+ export function writeCommunityCatalog(communityPath, incoming) {
282
+ const entries = incoming.map((e) => ({
283
+ id: e.id,
284
+ source: e.source,
285
+ name: e.name,
286
+ ...(e.nameEn ? { nameEn: e.nameEn } : {}),
287
+ ...(e.description ? { description: e.description } : {}),
288
+ ...(e.descriptionEn ? { descriptionEn: e.descriptionEn } : {}),
289
+ ...(e.icon ? { icon: e.icon } : {}),
290
+ ...(e.iconSvg ? { iconSvg: e.iconSvg } : {}),
291
+ ...(e.homepage ? { homepage: e.homepage } : {}),
292
+ }));
293
+ atomicWrite(communityPath, { entries });
294
+ return entries.length;
295
+ }
@@ -17,9 +17,9 @@
17
17
  * - activate 抛错只标记 error 字段并记日志,绝不影响主进程。
18
18
  */
19
19
  import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
20
- import { cpSync, existsSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync } from "node:fs";
20
+ import { cpSync, existsSync, lstatSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync, } from "node:fs";
21
21
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
22
- import { pathToFileURL, fileURLToPath } from "node:url";
22
+ import { pathToFileURL } from "node:url";
23
23
  import {} from "./protocol.js";
24
24
  import { UI_SLOTS } from "./plugin-ui-slots.js";
25
25
  import { LeftPanelRunningStore } from "./left-panel-running.js";
@@ -1174,9 +1174,15 @@ export class PluginManager {
1174
1174
  get customCatalogPath() {
1175
1175
  return join(this.dataDir, "plugin-catalog.json");
1176
1176
  }
1177
- /** 合并后的插件市场列表(builtin + 用户自定义,同 id 用户覆盖)。 */
1177
+ /** 官方社区生态插件清单文件(<dataDir>/community-catalog.json)。 */
1178
+ get communityCatalogPath() {
1179
+ return join(this.dataDir, "community-catalog.json");
1180
+ }
1181
+ /** 合并后的插件市场列表(builtin + community + 用户自定义,同 id 用户覆盖)。 */
1178
1182
  catalog() {
1179
- return this.builtinCatalogPath ? readCatalog(this.builtinCatalogPath, this.customCatalogPath) : [];
1183
+ return this.builtinCatalogPath
1184
+ ? readCatalog(this.builtinCatalogPath, this.customCatalogPath, this.communityCatalogPath)
1185
+ : [];
1180
1186
  }
1181
1187
  /** 插件市场列表纪元(随 plugin_catalog 消息下发)。 */
1182
1188
  get catalogEpochValue() {
@@ -1203,14 +1209,14 @@ export class PluginManager {
1203
1209
  return { error: err.message };
1204
1210
  }
1205
1211
  }
1206
- /** 移除一条用户自定义条目(builtin 不可经此删除);返回错误信息或 null。 */
1212
+ /** 移除一条用户自定义条目(builtin / 社区条目不可经此删除);返回错误信息或 null。 */
1207
1213
  removeCatalogEntry(id, lang) {
1208
1214
  const l = lang?.() ?? "en";
1209
1215
  try {
1210
1216
  const ok = removeCustomEntry(this.customCatalogPath, id);
1211
1217
  if (!ok)
1212
1218
  return {
1213
- error: pick(l, "未找到该条目,或它是内置条目(不可移除)", "Entry not found, or it is a built-in entry (cannot be removed)", "plugins.catalog.entry.cannot.remove"),
1219
+ error: pick(l, "未找到该条目,或它是内置/社区条目(不可移除)", "Entry not found, or it is a built-in/community entry (cannot be removed)", "plugins.catalog.entry.cannot.remove"),
1214
1220
  };
1215
1221
  this.catalogEpoch += 1;
1216
1222
  void this.pushCatalog();
@@ -2188,6 +2194,19 @@ export class PluginManager {
2188
2194
  if (pluginIds.has(this.proxyRoutes.get(prefix).pluginId))
2189
2195
  this.proxyRoutes.delete(prefix);
2190
2196
  }
2197
+ if (this.panelPushTimer) {
2198
+ clearTimeout(this.panelPushTimer);
2199
+ this.panelPushTimer = null;
2200
+ }
2201
+ if (this.panelSweepTimer) {
2202
+ clearInterval(this.panelSweepTimer);
2203
+ this.panelSweepTimer = null;
2204
+ }
2205
+ this.agentTools.clear();
2206
+ this.pluginCommands.clear();
2207
+ this.uiRuntime.clear();
2208
+ this.uiBase.clear();
2209
+ this.proxyRoutes.clear();
2191
2210
  this.pluginBgTasks.clear();
2192
2211
  this.loaded.clear();
2193
2212
  this.messageHandlers.clear();
@@ -2227,6 +2246,15 @@ export class PluginManager {
2227
2246
  continue;
2228
2247
  const targetDir = join(this.pluginsDir, name);
2229
2248
  const sourceDir = join(builtinDir, name);
2249
+ try {
2250
+ if (lstatSync(targetDir).isSymbolicLink()) {
2251
+ // 处于源码开发软链接模式(如 npm run plugins:link),直接使用源码,跳过随包文件覆盖
2252
+ continue;
2253
+ }
2254
+ }
2255
+ catch {
2256
+ /* lstat 失败走普通流程 */
2257
+ }
2230
2258
  const targetManifest = join(targetDir, "manifest.json");
2231
2259
  const sourceManifest = join(sourceDir, "manifest.json");
2232
2260
  if (!existsSync(sourceDir) || !existsSync(sourceManifest) || !existsSync(targetManifest)) {
@@ -3182,6 +3210,19 @@ export class PluginManager {
3182
3210
  const off = this.registerCommand(info.id, cmd);
3183
3211
  return effects.add(`command:/${String(cmd?.name ?? "?").replace(/^\/+/, "")}`, off);
3184
3212
  },
3213
+ execCommand: async (name, args, context) => {
3214
+ const hit = this.findCommand(name);
3215
+ if (!hit)
3216
+ return { ok: false, error: `未找到命令 /${name}` };
3217
+ try {
3218
+ const res = await hit.def.run(args, context ?? { clientId: `plugin:${info.id}` });
3219
+ return { ok: true, result: typeof res === "string" ? res : "" };
3220
+ }
3221
+ catch (err) {
3222
+ return { ok: false, error: err.message };
3223
+ }
3224
+ },
3225
+ getPluginCommands: () => this.listCommands(),
3185
3226
  storage,
3186
3227
  secrets,
3187
3228
  ensureDeps: (specs, opts) => ensurePluginDeps(dir, specs ?? [], opts?.onProgress),
@@ -21,10 +21,9 @@
21
21
  * 与副作用(createPresetIssue / fetchPresetCatalog)分开,便于单测。
22
22
  */
23
23
  import { execFile } from "node:child_process";
24
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
24
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
25
25
  import { tmpdir } from "node:os";
26
- import { dirname, join } from "node:path";
27
- import { fileURLToPath } from "node:url";
26
+ import { join } from "node:path";
28
27
  import { promisify } from "node:util";
29
28
  import { getAppVersion } from "./pkg-info.js";
30
29
  import { normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeUiLayout, } from "./client-state.js";