pi-web-ui 0.111.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +92 -2
  2. package/bin/frp-manager.mjs +9 -2
  3. package/bin/pi-web-ui.mjs +325 -45
  4. package/dist/server/agent-service-daemon.js +29 -4
  5. package/dist/server/agent-service.js +1527 -510
  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/canvas/canvas-agent-tool.js +8 -0
  11. package/dist/server/canvas/canvas-orchestrator.js +128 -22
  12. package/dist/server/canvas/pstack-skills-data.js +498 -0
  13. package/dist/server/client-state.js +28 -0
  14. package/dist/server/delegate-mode.js +6 -3
  15. package/dist/server/delegate-task.js +18 -3
  16. package/dist/server/dispatch-domain-handlers.js +39 -11
  17. package/dist/server/dsh/dsh-agent-service.js +294 -15
  18. package/dist/server/dsh/dsh-serialize.js +1 -1
  19. package/dist/server/durable/durable-driver.js +112 -107
  20. package/dist/server/durable/durable-event-projector.js +253 -0
  21. package/dist/server/durable/durable-loader.js +1 -14
  22. package/dist/server/durable/durable-models.js +107 -0
  23. package/dist/server/durable/index.js +0 -4
  24. package/dist/server/engine-probe.js +111 -48
  25. package/dist/server/eval-tool.js +28 -3
  26. package/dist/server/goal-service.js +7 -0
  27. package/dist/server/index.js +371 -57
  28. package/dist/server/json-utils.js +57 -0
  29. package/dist/server/marker-service.js +8 -0
  30. package/dist/server/message-window.js +43 -10
  31. package/dist/server/model-admin.js +247 -163
  32. package/dist/server/model-resolver.js +66 -44
  33. package/dist/server/plan-manager.js +3 -6
  34. package/dist/server/plugin-api-catalog.js +1 -0
  35. package/dist/server/plugin-assets.js +238 -0
  36. package/dist/server/plugin-facilities.js +22 -0
  37. package/dist/server/plugin-ui-slots.js +1 -0
  38. package/dist/server/plugins.js +209 -11
  39. package/dist/server/preset-fields.js +25 -1
  40. package/dist/server/preset-share.js +5 -2
  41. package/dist/server/prompt-assembler.js +2 -1
  42. package/dist/server/prompt-composer.js +18 -8
  43. package/dist/server/protocol-version.js +1 -1
  44. package/dist/server/queue-utils.js +156 -0
  45. package/dist/server/remote-ssh-service.js +110 -12
  46. package/dist/server/sdk-builtin-extensions.js +85 -0
  47. package/dist/server/serialize.js +1 -1
  48. package/dist/server/server-config.js +66 -0
  49. package/dist/server/session-parser.js +49 -13
  50. package/dist/server/session-search.js +4 -3
  51. package/dist/server/settings-service.js +74 -53
  52. package/dist/server/setup-page.js +632 -0
  53. package/dist/server/skill-discovery.js +361 -59
  54. package/dist/server/skill-maintenance.js +231 -0
  55. package/dist/server/skill-tool.js +32 -3
  56. package/dist/server/soft-cap.js +30 -6
  57. package/dist/server/subagent-helpers.js +22 -1
  58. package/dist/server/subagent-notify.js +93 -0
  59. package/dist/server/subagent-security-gate.js +282 -0
  60. package/dist/server/subagent-templates.js +8 -0
  61. package/dist/server/subagents.js +390 -48
  62. package/dist/server/terminals.js +196 -8
  63. package/dist/server/text-quote.js +61 -0
  64. package/dist/server/tool-approval.js +63 -4
  65. package/dist/server/tool-guards.js +208 -0
  66. package/dist/server/tool-host-factories.js +48 -10
  67. package/dist/server/tool-manager.js +106 -28
  68. package/dist/server/tool-overrides.js +21 -11
  69. package/dist/server/universal/driver-base.js +8 -0
  70. package/dist/server/universal/drivers/claude-code.js +116 -7
  71. package/dist/server/universal/drivers/dsh-driver.js +3 -0
  72. package/dist/server/universal/index.js +0 -1
  73. package/dist/server/universal/universal-session.js +106 -10
  74. package/dist/server/worktree-service.js +189 -1
  75. package/docs/dsh-engine.md +1 -5
  76. package/package.json +1 -1
  77. package/plugin-sdk/client-utils.mjs +192 -5
  78. package/plugin-sdk/index.d.ts +63 -1
  79. package/plugin-sdk/index.mjs +94 -0
  80. package/plugin-sdk/package.json +5 -1
  81. package/plugins/catalog.json +21 -0
  82. package/web/dist/assets/{TerminalPanel-BiUNySMA.js → TerminalPanel-3wojLfLk.js} +2 -2
  83. package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
  84. package/web/dist/assets/index-BwL7qBh6.css +1 -0
  85. package/web/dist/index.html +11 -2
  86. package/web/dist/sw.js +1 -1
  87. package/web/dist/assets/index-B0ajS__T.js +0 -697
  88. package/web/dist/assets/index-BHik5WGG.css +0 -1
@@ -6,16 +6,16 @@
6
6
  * 预设存取 + 何时需要 reload」,真正动 runtime 的 session.reload() 走宿主回调
7
7
  * (reloadSession 里还会刷新斜杠命令目录)。
8
8
  */
9
- import { existsSync, readdirSync, readFileSync } from "node:fs";
10
- import { homedir } from "node:os";
9
+ import { existsSync, readFileSync } from "node:fs";
11
10
  import { basename, dirname, join } from "node:path";
12
11
  import { fileURLToPath } from "node:url";
13
- import { extensionKey, isInternalExtension, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeKeepRecentMessages, normalizeSkillList, normalizeSkillsCatalogBudget, normalizeSkillsCatalogMaxDesc, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, settingsPresetToUi, } from "./client-state.js";
12
+ import { extensionKey, isInternalExtension, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeKeepRecentMessages, normalizeSkillList, normalizeSkillsCatalogBudget, normalizeSkillsCatalogMaxDesc, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, defaultSubagentAutoWakeMaxTurns, normalizeSubagentAutoWakeMaxTurns, settingsPresetToUi, } from "./client-state.js";
14
13
  import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
15
14
  import { findVisionModels, SYSTEM_PROMPT } from "./vision-bridge.js";
16
15
  import { COMMITMSG_SYSTEM_PROMPT } from "./scm-commitmsg.js";
17
16
  import { PLAN_MODE_SYSTEM_PROMPT } from "./plan-mode.js";
18
17
  import { DEFAULT_TEMPLATES, localizeTemplate } from "./subagent-templates.js";
18
+ import { discoverDiskSkills, isSkillStillOnDisk } from "./skill-discovery.js";
19
19
  import { deriveLegacy, foldLegacyIntoDisabled, normalizeDisabledAgentTools } from "./tool-manager.js";
20
20
  import { normalizeToolPromptOverrides } from "./tool-prompt-overrides.js";
21
21
  import { resolveServerLang } from "./i18n.js";
@@ -62,56 +62,21 @@ export class SettingsService {
62
62
  hasPendingReload() {
63
63
  return this.pendingReload;
64
64
  }
65
+ setPendingReload(v) {
66
+ this.pendingReload = v;
67
+ }
65
68
  consumePendingReload() {
66
69
  const v = this.pendingReload;
67
70
  this.pendingReload = false;
68
71
  return v;
69
72
  }
70
- /** 判断某个 skill 名是否仍存在于磁盘任何来源(agent 区 / 用户级或祖先
71
- * .agents/skills / 项目 .pi / npm 包内 skills)。被禁用且文件已删除的名字不应再
72
- * 出现在设置面板,也不应留在持久化记录里。 */
73
+ /** 判断某个 skill 名是否仍存在于磁盘任何来源(各类 Agent 项目区 / 全局 / 祖先 / npm 包等)。
74
+ * 被禁用且文件已删除的名字不应再出现在设置面板,也不应留在持久化记录里。 */
73
75
  skillStillOnDisk(name) {
74
- const cwd = this.host.cwd();
75
- const agentDir = this.host.agentDir();
76
- const check = (base) => existsSync(join(base, name)) || existsSync(join(base, `${name}.md`));
77
- // ① 用户区 <agentDir>/skills ② 项目 .pi/skills
78
- if (check(join(agentDir, "skills")))
79
- return true;
80
- // SDK 始终扫描用户级 ~/.agents/skills,不依赖 cwd 的祖先链(issue #669)。
81
- if (check(join(process.env.HOME || homedir(), ".agents", "skills")))
82
- return true;
83
- if (check(join(cwd, ".pi", "skills")))
84
- return true;
85
- // ③ 祖先链 .agents/skills(SDK collectAncestorAgentsSkillDirs 语义,最多上溯 6 层)
86
- let dir = cwd;
87
- for (let i = 0; i < 6 && dir !== dirname(dir); i++, dir = dirname(dir)) {
88
- if (check(join(dir, ".agents", "skills")))
89
- return true;
90
- }
91
- // ④ npm 包内 skills(agent 级 + 项目级,含 @scope 两级子包)
92
- for (const npmRoot of [join(agentDir, "npm", "node_modules"), join(cwd, ".pi", "npm", "node_modules")]) {
93
- try {
94
- for (const entry of readdirSync(npmRoot, { withFileTypes: true })) {
95
- if (!entry.isDirectory())
96
- continue;
97
- if (!entry.name.startsWith("@")) {
98
- if (check(join(npmRoot, entry.name, "skills")))
99
- return true;
100
- }
101
- else {
102
- for (const sub of readdirSync(join(npmRoot, entry.name), { withFileTypes: true })) {
103
- if (sub.isDirectory() && check(join(npmRoot, entry.name, sub.name, "skills"))) {
104
- return true;
105
- }
106
- }
107
- }
108
- }
109
- }
110
- catch {
111
- // npm 目录不存在/不可读 → 不是来源
112
- }
113
- }
114
- return false;
76
+ return isSkillStillOnDisk(name, {
77
+ cwd: this.host.cwd(),
78
+ agentDir: this.host.agentDir(),
79
+ });
115
80
  }
116
81
  /** 判断某个扩展 id 是否仍存在(loader 之外的兜底,供禁用残留清理用):
117
82
  * npm: 包 → 任一 npm 根还有目录,或还列在任一 settings.json packages 里
@@ -175,10 +140,19 @@ export class SettingsService {
175
140
  const loadedExts = allLoadedExts.filter((e) => !isInternalExtension(e));
176
141
  loadedSkillNames = new Set(loadedSkills.map((s) => s.name));
177
142
  loadedExtNames = new Set(loadedExts.map((e) => extensionKey(e)));
143
+ // 实时全源磁盘扫描:动态发现外部新安装/更新的各类 Agent 全局与本地技能
144
+ const diskSkills = discoverDiskSkills({
145
+ cwd: this.host.cwd(),
146
+ agentDir: this.host.agentDir(),
147
+ });
178
148
  // Prune entries that no longer exist on disk AND aren't disabled
179
149
  // (e.g. a skill/extension file was deleted). Disabled entries are
180
150
  // kept so they can be re-enabled even when filtered out of the loader.
181
- const keepSkills = new Set([...loadedSkills.map((s) => s.name), ...this.settings.disabledSkills]);
151
+ const keepSkills = new Set([
152
+ ...loadedSkills.map((s) => s.name),
153
+ ...diskSkills.map((s) => s.name),
154
+ ...this.settings.disabledSkills,
155
+ ]);
182
156
  const keepExts = new Set([
183
157
  ...loadedExts.map((e) => extensionKey(e)),
184
158
  ...this.settings.disabledExtensions.filter((id) => !isInternalExtension({ path: id })),
@@ -200,6 +174,18 @@ export class SettingsService {
200
174
  enabled: true,
201
175
  });
202
176
  }
177
+ for (const ds of diskSkills) {
178
+ if (!this.knownSkills.has(ds.name)) {
179
+ this.knownSkills.set(ds.name, {
180
+ name: ds.name,
181
+ description: ds.description,
182
+ enabled: !disabledSkills.has(ds.name),
183
+ });
184
+ }
185
+ else if (!this.knownSkills.get(ds.name).description && ds.description) {
186
+ this.knownSkills.get(ds.name).description = ds.description;
187
+ }
188
+ }
203
189
  for (const e of loadedExts) {
204
190
  const id = extensionKey(e);
205
191
  const p = e.sourceInfo?.path ?? e.path;
@@ -210,6 +196,11 @@ export class SettingsService {
210
196
  enabled: true,
211
197
  });
212
198
  }
199
+ // 若发现磁盘新增了 loader 尚未加载的技能,触发会话后台异步 reload 以刷新提示词和技能工具
200
+ const hasUnloadedDiskSkills = diskSkills.some((ds) => !loadedSkillNames.has(ds.name));
201
+ if (hasUnloadedDiskSkills && !this.host.isStreaming()) {
202
+ void this.host.reloadSession();
203
+ }
213
204
  }
214
205
  catch {
215
206
  // Session not ready yet — keep whatever we already know.
@@ -225,7 +216,7 @@ export class SettingsService {
225
216
  ...this.settings.reviewDisabledSkills,
226
217
  ...normalizeSkillList(this.settings.skillsFullText),
227
218
  ]),
228
- ].filter((name) => !loadedSkillNames.has(name) && !this.skillStillOnDisk(name));
219
+ ].filter((name) => !this.knownSkills.has(name) && !this.skillStillOnDisk(name));
229
220
  if (stale.length > 0) {
230
221
  this.settings.disabledSkills = this.settings.disabledSkills.filter((n) => !stale.includes(n));
231
222
  this.settings.reviewDisabledSkills = this.settings.reviewDisabledSkills.filter((n) => !stale.includes(n));
@@ -301,6 +292,7 @@ export class SettingsService {
301
292
  customSystemPrompt: this.settings.customSystemPrompt,
302
293
  promptTemplate: this.settings.promptTemplate ?? "",
303
294
  promptOverrides: { ...this.settings.promptOverrides },
295
+ promptDisabled: [...(this.settings.promptDisabled ?? [])],
304
296
  toolPromptOverrides: { ...this.settings.toolPromptOverrides },
305
297
  disabledAgentTools: [...normalizeDisabledAgentTools(this.settings.disabledAgentTools)],
306
298
  disabledPluginTools: [...normalizeDisabledPluginTools(this.settings.disabledPluginTools)],
@@ -373,6 +365,8 @@ export class SettingsService {
373
365
  subagentTemplates: this.templates.list().map((t) => localizeTemplate(t, this.host.getLocale?.())),
374
366
  subagentDefaultTemplates: DEFAULT_TEMPLATES.map((t) => t.name),
375
367
  subagentDefaultModel: this.settings.subagentDefaultModel ?? null,
368
+ subagentMaxDepth: this.settings.subagentMaxDepth ?? 0,
369
+ subagentAutoWakeMaxTurns: this.settings.subagentAutoWakeMaxTurns ?? defaultSubagentAutoWakeMaxTurns(),
376
370
  retryMaxAttempts: this.settings.retryMaxAttempts,
377
371
  softCapTokens: this.settings.softCapTokens,
378
372
  softCapByModel: { ...this.settings.softCapByModel },
@@ -433,6 +427,7 @@ export class SettingsService {
433
427
  partial.customSystemPrompt !== undefined ||
434
428
  partial.promptTemplate !== undefined ||
435
429
  partial.promptOverrides !== undefined ||
430
+ partial.promptDisabled !== undefined ||
436
431
  partial.disabledSkills !== undefined ||
437
432
  partial.disabledExtensions !== undefined;
438
433
  // 统一工具开关 live 生效(ActiveSet 加减,无需 reload),见末尾 applyToolGating。
@@ -463,6 +458,8 @@ export class SettingsService {
463
458
  }
464
459
  this.settings.promptOverrides = next;
465
460
  }
461
+ if (partial.promptDisabled !== undefined)
462
+ this.settings.promptDisabled = [...partial.promptDisabled];
466
463
  if (partial.toolPromptOverrides !== undefined) {
467
464
  // 逐工具合并:给出的键整体替换(归一化后为空 = 清除该工具覆盖)。
468
465
  const next = { ...this.settings.toolPromptOverrides };
@@ -652,6 +649,13 @@ export class SettingsService {
652
649
  const m = partial.subagentDefaultModel?.trim() ?? "";
653
650
  this.settings.subagentDefaultModel = m ? m : null;
654
651
  }
652
+ if (partial.subagentMaxDepth !== undefined) {
653
+ const n = Math.floor(Number(partial.subagentMaxDepth));
654
+ this.settings.subagentMaxDepth = Number.isFinite(n) && n > 0 ? n : 0;
655
+ }
656
+ if (partial.subagentAutoWakeMaxTurns !== undefined) {
657
+ this.settings.subagentAutoWakeMaxTurns = normalizeSubagentAutoWakeMaxTurns(partial.subagentAutoWakeMaxTurns);
658
+ }
655
659
  if (partial.retryMaxAttempts !== undefined) {
656
660
  // 出错重试次数:持久化 + 即时注入各会话(SDK 在每次退避前都重读
657
661
  // getRetrySettings,无需 reload runtime;见宿主 applyRetryOverrides)。
@@ -763,14 +767,19 @@ export class SettingsService {
763
767
  editSoftEnabled: presetLegacy.editSoftEnabled,
764
768
  };
765
769
  this.host.stateStore.saveSettings(this.host.clientId, this.settings);
766
- // 预设可能改了重试次数:即时注入(流式中延迟的 reload 之后还会由调用方重放)。
767
- this.host.applyRetryOverrides();
770
+ // 统一收口重放配置覆盖与工具门控(包含 retry/compaction/codemode 与 toolGating)
771
+ if (this.host.applySessionOverrides) {
772
+ this.host.applySessionOverrides();
773
+ }
774
+ else {
775
+ this.host.applyRetryOverrides();
776
+ this.host.applyCodemodeOverrides?.();
777
+ this.host.applyToolGating();
778
+ }
768
779
  this.push();
769
780
  if ((this.settings.showForkedParentSessions ?? false) !== prevShowForked) {
770
781
  this.host.onSessionsFilterChanged?.();
771
782
  }
772
- // 预设带了工具开关:live 应用(reload 路径会重放,流式中延迟到 agent_end)。
773
- this.host.applyToolGating();
774
783
  await this.applyRuntime();
775
784
  }
776
785
  /** Remove a named preset. */
@@ -972,6 +981,18 @@ export class SettingsService {
972
981
  }
973
982
  /** session.reload() + refresh the slash-command catalog + push state. */
974
983
  async applyReload() {
984
+ if (this.host.isDisposed())
985
+ return;
986
+ if (this.host.isStreaming()) {
987
+ this.pendingReload = true;
988
+ this.host.emit({
989
+ type: "notice",
990
+ level: "info",
991
+ text: "当前回复进行中,设置将在回复结束后自动应用",
992
+ textEn: "A reply is in progress; settings will apply when it finishes",
993
+ });
994
+ return;
995
+ }
975
996
  try {
976
997
  await this.host.reloadSession();
977
998
  this.push();