pi-web-ui 0.110.0 → 0.112.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 (110) hide show
  1. package/CHANGELOG.md +55 -2
  2. package/bin/frp-manager.mjs +92 -7
  3. package/dist/server/agent-formatters.js +10 -6
  4. package/dist/server/agent-service-daemon.js +27 -9
  5. package/dist/server/agent-service.js +1442 -489
  6. package/dist/server/approval-audit.js +119 -0
  7. package/dist/server/approval-default-rules.js +4 -4
  8. package/dist/server/approval-rules.js +42 -17
  9. package/dist/server/attachment-store.js +8 -8
  10. package/dist/server/attachments.js +114 -31
  11. package/dist/server/canvas/canvas-agent-tool.js +593 -0
  12. package/dist/server/canvas/canvas-cards.js +144 -0
  13. package/dist/server/canvas/canvas-dispatch.js +155 -0
  14. package/dist/server/canvas/canvas-orchestrator.js +1094 -0
  15. package/dist/server/canvas/canvas-store.js +260 -0
  16. package/dist/server/client-id-utils.js +2 -2
  17. package/dist/server/client-state.js +52 -0
  18. package/dist/server/context-budget.js +6 -3
  19. package/dist/server/delegate-mode.js +6 -3
  20. package/dist/server/delegate-task.js +18 -3
  21. package/dist/server/dispatch-domain-handlers.js +3 -0
  22. package/dist/server/dsh/dsh-agent-service.js +357 -20
  23. package/dist/server/dsh/dsh-client.js +10 -1
  24. package/dist/server/dsh/dsh-serialize.js +1 -1
  25. package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
  26. package/dist/server/dsh/runtime/launcher.mjs +59 -5
  27. package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
  28. package/dist/server/durable/durable-agent-service.js +3 -0
  29. package/dist/server/durable/durable-driver.js +75 -9
  30. package/dist/server/durable/durable-loader.js +1 -14
  31. package/dist/server/durable/durable-models.js +107 -0
  32. package/dist/server/durable/index.js +0 -4
  33. package/dist/server/engine-probe.js +76 -37
  34. package/dist/server/eval-tool.js +28 -3
  35. package/dist/server/file-transfer-routes.js +8 -2
  36. package/dist/server/files-service.js +10 -2
  37. package/dist/server/goal-service.js +7 -0
  38. package/dist/server/index.js +480 -59
  39. package/dist/server/json-utils.js +57 -0
  40. package/dist/server/marker-service.js +11 -1
  41. package/dist/server/markers/marker.js +45 -4
  42. package/dist/server/markers/registry.js +31 -0
  43. package/dist/server/message-window.js +44 -8
  44. package/dist/server/model-admin.js +68 -106
  45. package/dist/server/model-resolver.js +66 -44
  46. package/dist/server/office-parse.js +394 -7
  47. package/dist/server/plan-manager.js +3 -6
  48. package/dist/server/plugin-api-catalog.js +7 -0
  49. package/dist/server/plugin-assets.js +238 -0
  50. package/dist/server/plugin-facilities.js +22 -0
  51. package/dist/server/plugin-ui-slots.js +1 -0
  52. package/dist/server/plugins.js +296 -25
  53. package/dist/server/preset-fields.js +60 -2
  54. package/dist/server/preset-share.js +8 -2
  55. package/dist/server/prompt-assembler.js +9 -2
  56. package/dist/server/prompt-composer.js +84 -44
  57. package/dist/server/protocol-version.js +1 -1
  58. package/dist/server/queue-utils.js +156 -0
  59. package/dist/server/remote-ssh-service.js +16 -4
  60. package/dist/server/sdk-builtin-extensions.js +85 -0
  61. package/dist/server/server-config.js +66 -0
  62. package/dist/server/session-parser.js +49 -13
  63. package/dist/server/session-search.js +4 -3
  64. package/dist/server/settings-service.js +56 -7
  65. package/dist/server/soft-cap.js +8 -6
  66. package/dist/server/subagent-helpers.js +22 -1
  67. package/dist/server/subagent-notify.js +93 -0
  68. package/dist/server/subagent-security-gate.js +282 -0
  69. package/dist/server/subagent-templates.js +8 -0
  70. package/dist/server/subagents.js +144 -17
  71. package/dist/server/terminals.js +196 -8
  72. package/dist/server/text-quote.js +61 -0
  73. package/dist/server/tool-approval.js +63 -4
  74. package/dist/server/tool-guards.js +208 -0
  75. package/dist/server/tool-host-factories.js +46 -10
  76. package/dist/server/tool-manager.js +30 -0
  77. package/dist/server/tool-overrides.js +21 -11
  78. package/dist/server/univer-service.js +448 -0
  79. package/dist/server/universal/driver-base.js +8 -0
  80. package/dist/server/universal/drivers/claude-code.js +39 -5
  81. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  82. package/dist/server/universal/index.js +0 -1
  83. package/dist/server/universal/universal-attachments.js +5 -0
  84. package/dist/server/universal/universal-service.js +5 -0
  85. package/dist/server/universal/universal-session.js +114 -21
  86. package/dist/server/update-check.js +90 -5
  87. package/dist/server/workspace-snapshot.js +33 -2
  88. package/dist/server/worktree-service.js +189 -1
  89. package/docs/dsh-engine.md +493 -0
  90. package/package.json +5 -4
  91. package/plugin-sdk/client-utils.mjs +192 -5
  92. package/plugin-sdk/index.d.ts +80 -1
  93. package/plugin-sdk/index.mjs +99 -0
  94. package/plugin-sdk/package.json +5 -1
  95. package/plugins/catalog.json +33 -0
  96. package/themes/aetheris.css +114 -0
  97. package/themes/bases/obsidian-base.css +216 -0
  98. package/themes/md-preview.css +113 -0
  99. package/themes/wallpaper-flow.css +182 -0
  100. package/web/dist/assets/{TerminalPanel-BHjM6pzY.js → TerminalPanel-Dqr1dK28.js} +2 -2
  101. package/web/dist/assets/index-Dh8BX-lP.js +720 -0
  102. package/web/dist/assets/index-DqrC1I_a.css +1 -0
  103. package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
  104. package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
  105. package/web/dist/index.html +13 -4
  106. package/web/dist/sw.js +1 -1
  107. package/web/dist/assets/es-DIDZppIF.js +0 -2
  108. package/web/dist/assets/index-DwInT7-a.css +0 -1
  109. package/web/dist/assets/index-GfVFIgIL.js +0 -693
  110. package/web/dist/assets/markdown-CCeVCbci.css +0 -1
@@ -1,25 +1,10 @@
1
- /**
2
- * pi-web-ui 插件管理器 —— 可选界面组件的加载与桥接。
3
- *
4
- * 一个插件 = <dataDir>/plugins/<id>/ 目录:
5
- * manifest.json 元数据 { id?, name, version?, description? }(id 缺省取目录名)
6
- * index.mjs 服务端入口(可选):export default { activate(host) → deactivate? }
7
- * client/ 前端资源(可选),经 /plugins/<id>/client/* 以静态文件暴露;
8
- * entry.mjs 视图入口:export default { mount(el, ctx) → cleanup? }
9
- *
10
- * 设计要点:
11
- * - 不装即不存在:目录不在就没有任何协议/UI 痕迹;每次客户端 attach 时重扫目录,
12
- * 新丢进来的插件无需重启服务即可出现在顶栏(import 只做一次并缓存)。
13
- * - id 必须匹配 ID_RE,防路径穿越;client 静态服务同样逐段校验。
14
- * - host 窄接口:broadcast(pluginId, payload) 广播 plugin_data、onMessage 注册
15
- * 客户端上行处理、dataDir/cwd/log 环境。发送通道由 index.ts 注入(每个 socket
16
- * 的 send 函数),插件本身不接触 ws。
17
- * - activate 抛错只标记 error 字段并记日志,绝不影响主进程。
18
- */
1
+ import { registerMarker, unregisterMarker, isBuiltinMarker } from "./markers/index.js";
2
+ import { ensurePluginAsset, getPluginAssetStatus, } from "./plugin-assets.js";
19
3
  import { mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
20
- import { cpSync, existsSync, lstatSync, readFileSync, readdirSync, renameSync, watch as fsWatch, writeFileSync, } from "node:fs";
4
+ import { cpSync, existsSync, lstatSync, readFileSync, readdirSync, watch as fsWatch, writeFileSync } from "node:fs";
21
5
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
22
6
  import { pathToFileURL } from "node:url";
7
+ import { writeJsonAtomicSync } from "./atomic-file.js";
23
8
  import {} from "./protocol.js";
24
9
  import { UI_SLOTS } from "./plugin-ui-slots.js";
25
10
  import { LeftPanelRunningStore } from "./left-panel-running.js";
@@ -46,6 +31,8 @@ import { execFile } from "node:child_process";
46
31
  import { promisify } from "node:util";
47
32
  /** 合法插件 id:字母/数字/下划线/连字符,防路径穿越(同 themes.ts 的做法)。 */
48
33
  const ID_RE = /^[A-Za-z0-9_-]+$/;
34
+ /** 合法服务名:字母/数字/下划线/点/连字符,1-64 字符。 */
35
+ const SERVICE_NAME_RE = /^[A-Za-z0-9_.-]+$/;
49
36
  /** 交给插件前的防御性拷贝:provider 回的是快照管线的**活引用** —— messages 数组与
50
37
  * 元素对象都被 60ms 推送管线缓存复用(lastMessagesArray / uiMessageCache),插件原地
51
38
  * 改一个字段/挪一个元素,污染的就是推给真实客户端的快照。浅拷数组 + 元素对象
@@ -287,6 +274,7 @@ export const UI_SLOT_ALIASES = {
287
274
  "sidebar.right": "sidebar.right",
288
275
  leftbar: "sidebar.left",
289
276
  rightbar: "sidebar.right",
277
+ "tool.footer": "tool.card.footer",
290
278
  };
291
279
  /** 合法的条目种类(缺省 action;settings.pages 缺省 page)。 */
292
280
  export const UI_KINDS = new Set([
@@ -966,9 +954,7 @@ lang, secrets) {
966
954
  catch {
967
955
  /* 首次 */
968
956
  }
969
- const tmp = `${file}.tmp-${process.pid}`;
970
- writeFileSync(tmp, JSON.stringify({ ...existing, settings: persist }));
971
- renameSync(tmp, file);
957
+ writeJsonAtomicSync(file, { ...existing, settings: persist }, 0);
972
958
  });
973
959
  }
974
960
  catch (err) {
@@ -996,6 +982,10 @@ export class PluginManager {
996
982
  pluginBgTasks = new Map();
997
983
  /** 任务集合变化回调(index.ts 接到 AgentService,重推 bg_servers)。 */
998
984
  onBgTasksChanged = undefined;
985
+ /** 插件注册的内联标记:pluginId → (name → 定义)。 */
986
+ pluginMarkers = new Map();
987
+ /** 标记工具集合变化回调(index.ts 接到 AgentService,刷新各客户端 markers)。 */
988
+ onMarkersChanged = undefined;
999
989
  /** P3:左栏插件运行条目(见 left-panel-running.ts)。 */
1000
990
  panelRunning = new LeftPanelRunningStore();
1001
991
  panelPushTimer = null;
@@ -1037,6 +1027,10 @@ export class PluginManager {
1037
1027
  * 不落盘、随进程走;只经 plugin_data 按需拉取,绝不进 60ms 快照
1038
1028
  * (与 diagnostics 的“只读诊断随清单下发”正交,互不冲突)。 */
1039
1029
  pluginLogs = new Map();
1030
+ /** 插件间发布的服务表:serviceName → { pluginId: string; service: unknown } */
1031
+ pluginServices = new Map();
1032
+ /** 服务监听者表:serviceName → Set<(service: unknown | undefined) => void> */
1033
+ serviceListeners = new Map();
1040
1034
  constructor(dataDir, cwd,
1041
1035
  /** 随包发布的默认插件列表(<pkgRoot>/plugins/catalog.json)。缺省 = 无内置列表。 */
1042
1036
  builtinCatalogPath) {
@@ -1383,6 +1377,95 @@ export class PluginManager {
1383
1377
  return false;
1384
1378
  return this.proxyRoutes.delete(p);
1385
1379
  }
1380
+ /**
1381
+ * 插件发布一个命名服务。
1382
+ * 同名且被其它插件占有时抛错;同一插件重复 provide 时覆盖。
1383
+ * 返回注销函数(撤销自身发布并广播 undefined)。
1384
+ */
1385
+ provideService(pluginId, name, service) {
1386
+ const trimmed = String(name ?? "").trim();
1387
+ if (!trimmed || !SERVICE_NAME_RE.test(trimmed) || trimmed.length > 64) {
1388
+ throw new Error(`provide: 非法服务名 "${name}"(需由字母、数字、下划线、点或短横线组成,1-64 字符)`);
1389
+ }
1390
+ const existing = this.pluginServices.get(trimmed);
1391
+ if (existing && existing.pluginId !== pluginId) {
1392
+ throw new Error(`provide: 服务 "${trimmed}" 已由插件 "${existing.pluginId}" 注册`);
1393
+ }
1394
+ this.pluginServices.set(trimmed, { pluginId, service });
1395
+ const listeners = this.serviceListeners.get(trimmed);
1396
+ if (listeners) {
1397
+ for (const fn of listeners) {
1398
+ try {
1399
+ fn(service);
1400
+ }
1401
+ catch (err) {
1402
+ console.error(`[plugin:${pluginId}] service listener failed for "${trimmed}":`, err);
1403
+ }
1404
+ }
1405
+ }
1406
+ let revoked = false;
1407
+ return () => {
1408
+ if (revoked)
1409
+ return;
1410
+ revoked = true;
1411
+ const current = this.pluginServices.get(trimmed);
1412
+ if (current && current.pluginId === pluginId) {
1413
+ this.pluginServices.delete(trimmed);
1414
+ const currentListeners = this.serviceListeners.get(trimmed);
1415
+ if (currentListeners) {
1416
+ for (const fn of currentListeners) {
1417
+ try {
1418
+ fn(undefined);
1419
+ }
1420
+ catch (err) {
1421
+ console.error(`[plugin:${pluginId}] service revoked listener failed for "${trimmed}":`, err);
1422
+ }
1423
+ }
1424
+ }
1425
+ }
1426
+ };
1427
+ }
1428
+ getService(name) {
1429
+ const trimmed = String(name ?? "").trim();
1430
+ return this.pluginServices.get(trimmed)?.service;
1431
+ }
1432
+ hasService(name) {
1433
+ const trimmed = String(name ?? "").trim();
1434
+ return this.pluginServices.has(trimmed);
1435
+ }
1436
+ listServices() {
1437
+ const res = [];
1438
+ for (const [name, entry] of this.pluginServices.entries()) {
1439
+ res.push({ name, pluginId: entry.pluginId });
1440
+ }
1441
+ return res;
1442
+ }
1443
+ onService(name, handler) {
1444
+ const trimmed = String(name ?? "").trim();
1445
+ if (!trimmed || typeof handler !== "function")
1446
+ return () => { };
1447
+ let set = this.serviceListeners.get(trimmed);
1448
+ if (!set) {
1449
+ set = new Set();
1450
+ this.serviceListeners.set(trimmed, set);
1451
+ }
1452
+ set.add(handler);
1453
+ const current = this.pluginServices.get(trimmed);
1454
+ if (current !== undefined) {
1455
+ try {
1456
+ handler(current.service);
1457
+ }
1458
+ catch (err) {
1459
+ console.error(`[service:${trimmed}] initial onService handler failed:`, err);
1460
+ }
1461
+ }
1462
+ return () => {
1463
+ set?.delete(handler);
1464
+ if (set && set.size === 0) {
1465
+ this.serviceListeners.delete(trimmed);
1466
+ }
1467
+ };
1468
+ }
1386
1469
  /** index.ts 转发/upgrade 共用:请求路径的最长前缀命中(无命中返回 undefined)。
1387
1470
  * 查表前小写化:注册前缀统一小写归一,大小写混写也命中同一条。 */
1388
1471
  findProxy(path) {
@@ -1852,6 +1935,82 @@ export class PluginManager {
1852
1935
  }
1853
1936
  };
1854
1937
  }
1938
+ /** 注册内联标记(Inline Marker):跨插件重名拒绝,系统内置标记冲突拒绝。 */
1939
+ registerMarker(pluginId, marker) {
1940
+ if (!marker || typeof marker !== "object") {
1941
+ console.error(`[plugin:${pluginId}] registerMarker: 缺少 marker 参数,忽略`);
1942
+ this.pushRuntimeDiag(pluginId, "registerMarker: missing marker parameter, ignored");
1943
+ return () => { };
1944
+ }
1945
+ const name = String(marker.name ?? "").trim();
1946
+ if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) {
1947
+ console.error(`[plugin:${pluginId}] registerMarker: 非法名称「${marker.name}」(需英文字母开头,只允许字母数字_-),忽略`);
1948
+ this.pushRuntimeDiag(pluginId, `registerMarker: invalid name "${String(marker.name ?? "").slice(0, 32)}", ignored`);
1949
+ return () => { };
1950
+ }
1951
+ if (isBuiltinMarker(name)) {
1952
+ console.error(`[plugin:${pluginId}] registerMarker: 名称「${name}」为系统内置标记保留名称,忽略冲突注册`);
1953
+ this.pushRuntimeDiag(pluginId, `registerMarker: "${name}" conflicts with built-in marker, ignored`);
1954
+ return () => { };
1955
+ }
1956
+ if (typeof marker.apply !== "function") {
1957
+ console.error(`[plugin:${pluginId}] registerMarker: ${name} 缺少 apply 函数,忽略`);
1958
+ this.pushRuntimeDiag(pluginId, `marker "${name}": missing apply function, ignored`);
1959
+ return () => { };
1960
+ }
1961
+ if (!Array.isArray(marker.guidance) || marker.guidance.length === 0) {
1962
+ console.error(`[plugin:${pluginId}] registerMarker: ${name} 缺少 guidance 引导说明,忽略`);
1963
+ this.pushRuntimeDiag(pluginId, `marker "${name}": missing guidance, ignored`);
1964
+ return () => { };
1965
+ }
1966
+ for (const [pid, other] of this.pluginMarkers) {
1967
+ if (pid !== pluginId && other.has(name)) {
1968
+ console.error(`[plugin:${pluginId}] 标记 "${name}" 已被插件 ${pid} 注册,忽略重复`);
1969
+ this.pushRuntimeDiag(pluginId, `marker "${name}": already registered by plugin ${pid}, ignored`);
1970
+ return () => { };
1971
+ }
1972
+ }
1973
+ let table = this.pluginMarkers.get(pluginId);
1974
+ if (!table)
1975
+ this.pluginMarkers.set(pluginId, (table = new Map()));
1976
+ if (table.has(name)) {
1977
+ console.error(`[plugin:${pluginId}] 标记 "${name}" 重复注册,忽略`);
1978
+ this.pushRuntimeDiag(pluginId, `marker "${name}": duplicate registration, ignored`);
1979
+ return () => { };
1980
+ }
1981
+ const markerTool = {
1982
+ name,
1983
+ label: marker.label ? String(marker.label).slice(0, 80) : undefined,
1984
+ pluginId,
1985
+ guidance: [...marker.guidance],
1986
+ getGuidance: marker.getGuidance,
1987
+ apply: marker.apply,
1988
+ overlay: marker.overlay,
1989
+ init: marker.init,
1990
+ };
1991
+ table.set(name, markerTool);
1992
+ registerMarker(markerTool);
1993
+ console.log(`[plugin:${pluginId}] registered inline marker: ${name}`);
1994
+ try {
1995
+ this.onMarkersChanged?.();
1996
+ }
1997
+ catch (err) {
1998
+ console.error("[plugins] onMarkersChanged failed:", err);
1999
+ }
2000
+ return () => {
2001
+ if (table.delete(name)) {
2002
+ if (table.size === 0)
2003
+ this.pluginMarkers.delete(pluginId);
2004
+ unregisterMarker(name);
2005
+ try {
2006
+ this.onMarkersChanged?.();
2007
+ }
2008
+ catch {
2009
+ /* shutting down */
2010
+ }
2011
+ }
2012
+ };
2013
+ }
1855
2014
  /** 注册斜杠命令:跨插件重名拒绝(先注册者胜出),onCommandsChanged 通知目录刷新。 */
1856
2015
  registerCommand(pluginId, cmd) {
1857
2016
  const name = String(cmd?.name ?? "").replace(/^\/+/, ""); // 容忍误带的前导 /
@@ -2127,6 +2286,21 @@ export class PluginManager {
2127
2286
  if (hit.pluginId === p.info.id)
2128
2287
  this.proxyRoutes.delete(prefix);
2129
2288
  }
2289
+ // ③ 兜底:回收该插件发布的服务
2290
+ for (const [name, hit] of this.pluginServices) {
2291
+ if (hit.pluginId === p.info.id) {
2292
+ this.pluginServices.delete(name);
2293
+ const listeners = this.serviceListeners.get(name);
2294
+ if (listeners) {
2295
+ for (const fn of listeners) {
2296
+ try {
2297
+ fn(undefined);
2298
+ }
2299
+ catch { }
2300
+ }
2301
+ }
2302
+ }
2303
+ }
2130
2304
  }
2131
2305
  /** 反激活单个插件:deactivate + 注销 AI 工具 + 清缓存。
2132
2306
  *
@@ -2194,6 +2368,9 @@ export class PluginManager {
2194
2368
  if (pluginIds.has(this.proxyRoutes.get(prefix).pluginId))
2195
2369
  this.proxyRoutes.delete(prefix);
2196
2370
  }
2371
+ // ④ 兜底:清理插件间服务
2372
+ this.pluginServices.clear();
2373
+ this.serviceListeners.clear();
2197
2374
  if (this.panelPushTimer) {
2198
2375
  clearTimeout(this.panelPushTimer);
2199
2376
  this.panelPushTimer = null;
@@ -2203,6 +2380,7 @@ export class PluginManager {
2203
2380
  this.panelSweepTimer = null;
2204
2381
  }
2205
2382
  this.agentTools.clear();
2383
+ this.pluginMarkers.clear();
2206
2384
  this.pluginCommands.clear();
2207
2385
  this.uiRuntime.clear();
2208
2386
  this.uiBase.clear();
@@ -2225,6 +2403,17 @@ export class PluginManager {
2225
2403
  const builtinDir = dirname(this.builtinCatalogPath);
2226
2404
  if (!existsSync(builtinDir))
2227
2405
  return;
2406
+ // 确保数据目录下同步最新 plugin-sdk(供官方与自定义插件共享纯 ESM 工具层)
2407
+ const builtinSdkDir = join(dirname(builtinDir), "plugin-sdk");
2408
+ const targetSdkDir = join(this.dataDir, "plugin-sdk");
2409
+ if (existsSync(builtinSdkDir)) {
2410
+ try {
2411
+ cpSync(builtinSdkDir, targetSdkDir, { recursive: true });
2412
+ }
2413
+ catch {
2414
+ /* best-effort */
2415
+ }
2416
+ }
2228
2417
  let names;
2229
2418
  try {
2230
2419
  names = readdirSync(this.pluginsDir);
@@ -2296,8 +2485,15 @@ export class PluginManager {
2296
2485
  continue;
2297
2486
  const dir = join(this.pluginsDir, name);
2298
2487
  try {
2299
- if (!(await stat(dir)).isDirectory())
2488
+ const st = await stat(dir);
2489
+ if (!st.isDirectory())
2300
2490
  continue;
2491
+ }
2492
+ catch {
2493
+ // 目录不存在(如失效的软链接)或非目录/不可访问,跳过
2494
+ continue;
2495
+ }
2496
+ try {
2301
2497
  const raw = await readFile(join(dir, "manifest.json"), "utf8");
2302
2498
  // wantsDom 快照供静态门禁用(manifest 坏了 → JSON.parse 抛 → catch 跳过,旧快照残留无害:门禁只拦「快照里要且没授权」的)。
2303
2499
  const m = JSON.parse(raw);
@@ -2395,6 +2591,7 @@ export class PluginManager {
2395
2591
  settingsSchema: settingsSchemaForScan,
2396
2592
  settingsValues: resolvedSettingsForScan.values,
2397
2593
  settingsSources: resolvedSettingsForScan.sources,
2594
+ isolated: m.isolated === true || m.shadow === true ? true : undefined,
2398
2595
  // 可渲染的 fenced-code 语言(manifest "renderers")——前端据此按需加载
2399
2596
  renderers: Array.isArray(m.renderers)
2400
2597
  ? m.renderers.filter((r) => typeof r === "string" && r.length > 0).slice(0, 32)
@@ -2807,7 +3004,7 @@ export class PluginManager {
2807
3004
  if (!targetReal)
2808
3005
  throw new Error(`无法解析真实路径:${abs}`);
2809
3006
  const granted = self.grants.list().find((g) => g.pluginId === info.id)?.paths ?? [];
2810
- for (const r of [self.cwdValue, ...granted]) {
3007
+ for (const r of [self.cwdValue, ...self.workspaceRoots, ...granted]) {
2811
3008
  const rootReal = realPathOfNearest(resolve(r)) ?? resolve(r);
2812
3009
  if (isInsideRoot(rootReal, targetReal))
2813
3010
  return;
@@ -2946,6 +3143,7 @@ export class PluginManager {
2946
3143
  passthrough.thinkingLevel = thinkingLevel.slice(0, 64);
2947
3144
  return self.chatProvider(info.id, passthrough);
2948
3145
  };
3146
+ let pluginAbort = null;
2949
3147
  const host = {
2950
3148
  broadcast: (payload) => this.broadcast(info.id, payload),
2951
3149
  notify: (level, text, textEn) => this.notifyAll(level, text, textEn),
@@ -3224,13 +3422,29 @@ export class PluginManager {
3224
3422
  },
3225
3423
  getPluginCommands: () => this.listCommands(),
3226
3424
  storage,
3425
+ services: {
3426
+ provide: (name, service) => {
3427
+ const revoke = self.provideService(info.id, name, service);
3428
+ return effects.add(`service:${name}`, revoke);
3429
+ },
3430
+ get: (name) => self.getService(name),
3431
+ has: (name) => self.hasService(name),
3432
+ list: () => self.listServices(),
3433
+ on: (name, handler) => {
3434
+ const off = self.onService(name, handler);
3435
+ return effects.add(`service_listener:${name}`, off);
3436
+ },
3437
+ },
3438
+ provide: (name, service) => host.services.provide(name, service),
3439
+ get: (name) => host.services.get(name),
3440
+ onService: (name, handler) => host.services.on(name, handler),
3227
3441
  secrets,
3228
3442
  ensureDeps: (specs, opts) => ensurePluginDeps(dir, specs ?? [], opts?.onProgress),
3229
3443
  route: (method, path, handler) => {
3230
3444
  if (!can("http"))
3231
3445
  return () => { };
3232
3446
  const m = String(method ?? "GET").toUpperCase();
3233
- if (!["GET", "POST", "PUT", "DELETE"].includes(m) ||
3447
+ if (!["GET", "POST", "PUT", "DELETE", "OPTIONS"].includes(m) ||
3234
3448
  typeof path !== "string" ||
3235
3449
  !path.startsWith("/") ||
3236
3450
  typeof handler !== "function") {
@@ -3262,6 +3476,12 @@ export class PluginManager {
3262
3476
  const off = this.registerAgentTool(info.id, tool);
3263
3477
  return effects.add(`agentTool:${String(tool?.name ?? "?")}`, off);
3264
3478
  },
3479
+ registerMarker: (marker) => {
3480
+ if (!can("tools"))
3481
+ return () => { };
3482
+ const off = this.registerMarker(info.id, marker);
3483
+ return effects.add(`marker:${String(marker?.name ?? "?")}`, off);
3484
+ },
3265
3485
  registerTool: (tool) => {
3266
3486
  if (!can("tools"))
3267
3487
  return () => { };
@@ -4122,6 +4342,48 @@ export class PluginManager {
4122
4342
  .slice(0, 64) || "anonymous";
4123
4343
  return effects.add(`plugin:${name}`, dispose);
4124
4344
  },
4345
+ resolveInWorkspace: (relOrAbsPath) => {
4346
+ const target = resolve(self.cwdValue, String(relOrAbsPath ?? ""));
4347
+ if (!self.isInsideWorkspace(target)) {
4348
+ const err = new Error("路径超出工作区范围");
4349
+ err.statusCode = 403;
4350
+ throw err;
4351
+ }
4352
+ return target;
4353
+ },
4354
+ fetch: async (input, init) => {
4355
+ if (!pluginAbort) {
4356
+ pluginAbort = new AbortController();
4357
+ effects.add("plugin:fetch-abort", () => {
4358
+ try {
4359
+ pluginAbort?.abort();
4360
+ }
4361
+ catch { }
4362
+ });
4363
+ }
4364
+ const timeoutMs = Math.max(100, Math.min(Number(init?.timeoutMs ?? 30_000) || 30_000, 600_000));
4365
+ const timeoutSignal = AbortSignal.timeout(timeoutMs);
4366
+ const signals = [pluginAbort.signal, timeoutSignal];
4367
+ if (init?.signal)
4368
+ signals.push(init.signal);
4369
+ const combinedSignal = AbortSignal.any
4370
+ ? AbortSignal.any(signals)
4371
+ : init?.signal || timeoutSignal;
4372
+ return await fetch(input, {
4373
+ ...init,
4374
+ signal: combinedSignal,
4375
+ });
4376
+ },
4377
+ assets: {
4378
+ ensure: (spec, opts) => {
4379
+ return ensurePluginAsset(dir, spec, {
4380
+ ...opts,
4381
+ signal: pluginAbort?.signal,
4382
+ log: (msg) => host.log(msg),
4383
+ });
4384
+ },
4385
+ status: (spec) => getPluginAssetStatus(dir, spec),
4386
+ },
4125
4387
  };
4126
4388
  try {
4127
4389
  // Node 对同一 URL 的 import() 永远返回缓存模块——追加 epoch 作查询串
@@ -4196,12 +4458,21 @@ export function resolvePluginClientFile(pluginsDir, id, rest) {
4196
4458
  return null;
4197
4459
  return abs;
4198
4460
  }
4461
+ /** 解析插件公共模块静态文件绝对路径(防止路径穿越)。 */
4462
+ export function resolvePluginSharedFile(sharedDir, rest) {
4463
+ const root = resolve(sharedDir);
4464
+ const abs = resolve(root, rest);
4465
+ if (abs !== root && !abs.startsWith(root + sep))
4466
+ return null;
4467
+ return abs;
4468
+ }
4199
4469
  /** 通用代理前缀的保留字:命中即拒绝注册(宿主自用路径,代理抢了会吞掉主站功能)。 */
4200
4470
  export const PROXY_RESERVED_PREFIXES = [
4201
4471
  "/api",
4202
4472
  "/ws",
4203
4473
  "/plugins",
4204
4474
  "/plugins-api",
4475
+ "/plugins-shared",
4205
4476
  "/assets",
4206
4477
  "/icons",
4207
4478
  "/themes",
@@ -30,6 +30,7 @@ export const PRESET_FIELD_GROUPS = {
30
30
  "customSystemPrompt",
31
31
  "promptTemplate",
32
32
  "promptOverrides",
33
+ "promptDisabled",
33
34
  "reviewPrompt",
34
35
  "reviewDisabledSkills",
35
36
  ],
@@ -51,13 +52,22 @@ export const PRESET_FIELD_GROUPS = {
51
52
  // 终端接管
52
53
  terminal: ["terminalBash", "terminalBashIdleMs", "terminalBashMaxForegroundMs"],
53
54
  // 技能与扩展
54
- skills: ["disabledSkills", "disabledExtensions", "skillsFullText"],
55
+ skills: [
56
+ "disabledSkills",
57
+ "disabledExtensions",
58
+ "skillsFullText",
59
+ "skillsCatalogMaxDesc",
60
+ "skillsCatalogShowLocation",
61
+ "skillsCatalogBudget",
62
+ ],
55
63
  // 模型侧行为与各专用提示词
56
64
  ai: [
57
65
  "retryMaxAttempts",
58
66
  "softCapTokens",
59
67
  "softCapByModel",
60
68
  "subagentDefaultModel",
69
+ "subagentMaxDepth",
70
+ "subagentAutoWakeMaxTurns",
61
71
  "visionBridgeEnabled",
62
72
  "visionBridgeModel",
63
73
  "visionBridgePromptMode",
@@ -166,6 +176,12 @@ export const PRESET_FIELD_META = {
166
176
  hintZh: "仅在目标审查阶段禁止审查者调用的技能列表",
167
177
  hintEn: "Skills unavailable to the reviewer in Goal Mode",
168
178
  },
179
+ promptDisabled: {
180
+ labelZh: "禁用的提示词段",
181
+ labelEn: "Disabled Prompt Sections",
182
+ hintZh: "组合模板中不渲染的提示词段(如 soul/skills)",
183
+ hintEn: "Prompt sections excluded from the composed template",
184
+ },
169
185
  // tools
170
186
  disabledAgentTools: {
171
187
  labelZh: "禁用的内置工具",
@@ -283,6 +299,24 @@ export const PRESET_FIELD_META = {
283
299
  hintZh: "将指定技能的完整正文直接注入上下文,跳过 skill 工具按需载入",
284
300
  hintEn: "Inject full text of selected skills directly into context",
285
301
  },
302
+ skillsCatalogMaxDesc: {
303
+ labelZh: "技能描述截断字符数",
304
+ labelEn: "Skill Description Cap",
305
+ hintZh: "名录中单条技能描述最大字符数(默认 250,0 为不截断)",
306
+ hintEn: "Max characters per skill description in catalog (default 250, 0 to disable)",
307
+ },
308
+ skillsCatalogShowLocation: {
309
+ labelZh: "名录显示物理路径",
310
+ labelEn: "Show Skill Location",
311
+ hintZh: "是否在技能名录中输出 location 文件绝对路径(默认关,避免浪费 token 和泄露路径)",
312
+ hintEn: "Whether to output file path in skill catalog (default off to save tokens and prevent path leak)",
313
+ },
314
+ skillsCatalogBudget: {
315
+ labelZh: "技能名录总字符预算",
316
+ labelEn: "Skill Catalog Budget",
317
+ hintZh: "技能名录字符上限(默认 20000),超限自动降级为紧凑名称索引",
318
+ hintEn: "Total catalog character limit (default 20000), falls back to compact name index when exceeded",
319
+ },
286
320
  // ai
287
321
  retryMaxAttempts: {
288
322
  labelZh: "网络重试上限",
@@ -308,6 +342,18 @@ export const PRESET_FIELD_META = {
308
342
  hintZh: "派生子代理时优先使用的专用模型(留空跟随主对话)",
309
343
  hintEn: "Dedicated model for subagents (empty to follow main chat)",
310
344
  },
345
+ subagentMaxDepth: {
346
+ labelZh: "子代理最大嵌套层数",
347
+ labelEn: "Subagent Max Depth",
348
+ hintZh: "主对话下最多几层子代理(0 = 不限制,1 = 子代理不能再派发)",
349
+ hintEn: "Max subagent layers below the main chat (0 = unlimited, 1 = subagents cannot spawn)",
350
+ },
351
+ subagentAutoWakeMaxTurns: {
352
+ labelZh: "子代理自动唤醒轮数上限",
353
+ labelEn: "Subagent Max Auto-Wake Rounds",
354
+ hintZh: "连续自动唤醒父对话的最大轮数(默认 5,0 = 不限制,挂起期间通知不丢)",
355
+ hintEn: "Max consecutive autonomous wake rounds (default 5, 0 = unlimited; buffered on suspend)",
356
+ },
311
357
  visionBridgeEnabled: {
312
358
  labelZh: "视觉桥 (看图转写)",
313
359
  labelEn: "Vision Bridge",
@@ -577,7 +623,10 @@ export function formatPresetFieldValue(field, value, lang = "zh") {
577
623
  };
578
624
  }
579
625
  // 4. 技能 / 扩展禁用列表
580
- if (field === "disabledSkills" || field === "disabledExtensions" || field === "reviewDisabledSkills") {
626
+ if (field === "disabledSkills" ||
627
+ field === "disabledExtensions" ||
628
+ field === "reviewDisabledSkills" ||
629
+ field === "promptDisabled") {
581
630
  const list = Array.isArray(value) ? value.filter((x) => typeof x === "string" && Boolean(x)) : [];
582
631
  if (list.length === 0) {
583
632
  return { summary: isZh ? "全部启用(无禁用)" : "All enabled (none disabled)" };
@@ -602,6 +651,15 @@ export function formatPresetFieldValue(field, value, lang = "zh") {
602
651
  detail: list.map((item) => `- ${item}`).join("\n"),
603
652
  };
604
653
  }
654
+ if (field === "skillsCatalogMaxDesc" || field === "skillsCatalogBudget") {
655
+ const n = Number(value);
656
+ const zeroText = isZh ? "不限" : "No limit";
657
+ const valText = n === 0 ? zeroText : isZh ? `${n} 字符` : `${n} chars`;
658
+ return { summary: valText };
659
+ }
660
+ if (field === "skillsCatalogShowLocation") {
661
+ return { summary: value ? (isZh ? "开启" : "Enabled") : isZh ? "关闭" : "Disabled" };
662
+ }
605
663
  // 6. 提示词文本
606
664
  if (field === "customSystemPrompt" ||
607
665
  field === "promptTemplate" ||
@@ -31,10 +31,9 @@ import { pick } from "./i18n.js";
31
31
  import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
32
32
  import { ALL_KNOWN_AGENT_TOOL_NAMES, isConfigurableAgentTool, normalizeDisabledAgentTools, resolveDisabledAgentToolsFromEnabled, resolveEnabledAgentTools, } from "./tool-manager.js";
33
33
  import { normalizeToolPromptOverrides } from "./tool-prompt-overrides.js";
34
- import { isBlockedHost, isNativeGlobalFetch, resolveAndValidateUrl, validateFetchUrl, } from "./net-guard.js";
34
+ import { isNativeGlobalFetch, resolveAndValidateUrl, validateFetchUrl } from "./net-guard.js";
35
35
  import { PRESET_FIELD_NAMES, normalizePresetFieldSelection } from "./preset-fields.js";
36
36
  import { defaultFetcher } from "./update-check.js";
37
- export { isBlockedHost, resolveAndValidateUrl, validateFetchUrl };
38
37
  const execFileAsync = promisify(execFile);
39
38
  /** 预览文本的截断长度(设置面板展示用)。 */
40
39
  const PREVIEW_TEXT_MAX = 400;
@@ -226,6 +225,7 @@ const PRESET_FIELD_KINDS = {
226
225
  customSystemPrompt: "text",
227
226
  promptTemplate: "text",
228
227
  promptOverrides: "textMap",
228
+ promptDisabled: "list",
229
229
  reviewPrompt: "text",
230
230
  reviewDisabledSkills: "list",
231
231
  // -- tools -----------------------------------------------------------
@@ -250,11 +250,16 @@ const PRESET_FIELD_KINDS = {
250
250
  disabledSkills: "list",
251
251
  disabledExtensions: "list",
252
252
  skillsFullText: "list",
253
+ skillsCatalogMaxDesc: "number",
254
+ skillsCatalogShowLocation: "bool",
255
+ skillsCatalogBudget: "number",
253
256
  // -- ai --------------------------------------------------------------
254
257
  retryMaxAttempts: "retry",
255
258
  softCapTokens: "softCap",
256
259
  softCapByModel: "softCapByModel",
257
260
  subagentDefaultModel: "nullableString",
261
+ subagentMaxDepth: "number",
262
+ subagentAutoWakeMaxTurns: "number",
258
263
  visionBridgeEnabled: "bool",
259
264
  visionBridgeModel: "nullableString",
260
265
  visionBridgePromptMode: "promptMode",
@@ -989,6 +994,7 @@ export function buildImportPreview(name, doc, sanitized, replaces) {
989
994
  reviewPrompt: (preset.reviewPrompt ?? "").slice(0, PREVIEW_TEXT_MAX),
990
995
  disabledSkills: preset.disabledSkills ?? [],
991
996
  disabledExtensions: preset.disabledExtensions ?? [],
997
+ promptDisabled: preset.promptDisabled ?? [],
992
998
  };
993
999
  }
994
1000
  /** preset_import / preset_import_url 的共同后段:预览 →(非 dryRun)落盘 →(可选)应用。 */
@@ -64,7 +64,14 @@ export function shouldRenderMainCompose(opts) {
64
64
  const ovs = opts.promptOverrides ?? {};
65
65
  const hasOverride = Object.values(ovs).some((v) => typeof v === "string" && v.trim());
66
66
  const preset = opts.preset ?? "standard";
67
- return !!tpl || hasOverride || preset !== "standard" || opts.disabledToolCount > 0 || opts.isLazy === true;
67
+ return (!!tpl ||
68
+ hasOverride ||
69
+ (opts.promptDisabled?.length ?? 0) > 0 ||
70
+ preset !== "standard" ||
71
+ opts.disabledToolCount > 0 ||
72
+ opts.isLazy === true ||
73
+ opts.hasSkills === true ||
74
+ opts.hasSkillsFullText === true);
68
75
  }
69
76
  /**
70
77
  * 渲染组合模板。非定制状态返回 undefined 让 SDK 内部装配。
@@ -76,5 +83,5 @@ export function renderMainCompose(inputs, opts) {
76
83
  const tpl = (opts.promptTemplate ?? "").trim();
77
84
  const ovs = opts.promptOverrides ?? {};
78
85
  const hasOverride = Object.values(ovs).some((v) => typeof v === "string" && v.trim());
79
- return renderPromptTemplate(tpl || DEFAULT_PROMPT_TEMPLATE, texts, hasOverride ? ovs : undefined);
86
+ return renderPromptTemplate(tpl || DEFAULT_PROMPT_TEMPLATE, texts, hasOverride ? ovs : undefined, new Set(opts.promptDisabled ?? []));
80
87
  }