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.
Files changed (109) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/README.md +48 -45
  3. package/README.zh-CN.md +43 -40
  4. package/bin/pi-web-ui.mjs +172 -40
  5. package/dist/server/agent-formatters.js +191 -0
  6. package/dist/server/agent-service-daemon.js +1266 -0
  7. package/dist/server/agent-service.js +9851 -11892
  8. package/dist/server/approval-default-rules.js +158 -0
  9. package/dist/server/approval-rules.js +130 -184
  10. package/dist/server/ask-user-question-tool.js +94 -0
  11. package/dist/server/attachment-store.js +38 -1
  12. package/dist/server/attachments.js +55 -0
  13. package/dist/server/bash-tool.js +83 -0
  14. package/dist/server/bg-servers.js +82 -2
  15. package/dist/server/browser-page-tool.js +207 -0
  16. package/dist/server/claim-files-tool.js +4 -4
  17. package/dist/server/client-id-utils.js +51 -0
  18. package/dist/server/client-state.js +63 -1
  19. package/dist/server/compact-context-tool.js +10 -9
  20. package/dist/server/compaction-markers.js +34 -1
  21. package/dist/server/context-budget-runner.js +43 -0
  22. package/dist/server/conversation-read-tool.js +7 -8
  23. package/dist/server/conversation-touches.js +19 -0
  24. package/dist/server/dangling-tools.js +18 -5
  25. package/dist/server/delegate-mode.js +1 -0
  26. package/dist/server/delegate-task.js +10 -14
  27. package/dist/server/dispatch-domain-handlers.js +631 -0
  28. package/dist/server/dispatch-plugin-handlers.js +300 -0
  29. package/dist/server/dsh/dsh-agent-service.js +125 -13
  30. package/dist/server/edit-soft-tool.js +10 -12
  31. package/dist/server/eval-tool.js +4 -5
  32. package/dist/server/goal-evidence.js +180 -0
  33. package/dist/server/goal-service.js +49 -9
  34. package/dist/server/hashline-engine.js +199 -32
  35. package/dist/server/index.js +212 -944
  36. package/dist/server/left-panel-running.js +115 -0
  37. package/dist/server/load-tools-tool.js +100 -0
  38. package/dist/server/lsp-tool.js +50 -28
  39. package/dist/server/marker-service.js +53 -12
  40. package/dist/server/markers/builtins/action.js +108 -0
  41. package/dist/server/markers/index.js +4 -1
  42. package/dist/server/markers-list-tool.js +34 -0
  43. package/dist/server/market-service.js +277 -0
  44. package/dist/server/mcp-bridge.js +137 -30
  45. package/dist/server/mcp-hot-reload.js +84 -27
  46. package/dist/server/mcp-manager.js +215 -0
  47. package/dist/server/message-entry-resolver.js +32 -0
  48. package/dist/server/orphan-manager.js +44 -0
  49. package/dist/server/patch-remote-catalog.js +28 -10
  50. package/dist/server/patch-tool.js +9 -8
  51. package/dist/server/persona-chain.js +63 -0
  52. package/dist/server/plan-mode.js +9 -6
  53. package/dist/server/plan-update-tool.js +96 -0
  54. package/dist/server/plugin-api-catalog.js +30 -3
  55. package/dist/server/plugin-conversation-view.js +47 -0
  56. package/dist/server/plugin-facilities.js +13 -3
  57. package/dist/server/plugin-ui-slots.js +39 -0
  58. package/dist/server/plugins.js +183 -63
  59. package/dist/server/present-files-tool.js +10 -11
  60. package/dist/server/preset-fields.js +700 -0
  61. package/dist/server/preset-share.js +1179 -0
  62. package/dist/server/process-utils.js +30 -0
  63. package/dist/server/prompt-assembler.js +80 -0
  64. package/dist/server/prompt-composer.js +23 -9
  65. package/dist/server/protocol-version.js +1 -1
  66. package/dist/server/read-tool.js +8 -10
  67. package/dist/server/resolve-global-sdk.js +80 -18
  68. package/dist/server/schedule-agent-tool.js +147 -146
  69. package/dist/server/scm-commitmsg.js +74 -0
  70. package/dist/server/sdk-origin.js +125 -37
  71. package/dist/server/serialize.js +97 -7
  72. package/dist/server/session-branch.js +367 -0
  73. package/dist/server/session-parser.js +235 -0
  74. package/dist/server/session-search.js +158 -0
  75. package/dist/server/settings-service.js +115 -84
  76. package/dist/server/skill-content-filler.js +33 -0
  77. package/dist/server/skill-tool.js +3 -4
  78. package/dist/server/subagent-handoff.js +18 -0
  79. package/dist/server/subagent-helpers.js +88 -0
  80. package/dist/server/subagents.js +15 -22
  81. package/dist/server/terminals.js +171 -91
  82. package/dist/server/tool-approval.js +3 -1
  83. package/dist/server/tool-guards.js +527 -0
  84. package/dist/server/tool-host-factories.js +217 -0
  85. package/dist/server/tool-manager.js +84 -23
  86. package/dist/server/tool-prompt-overrides.js +158 -0
  87. package/dist/server/tool-prompts.js +42 -0
  88. package/dist/server/tool-signature.js +104 -0
  89. package/dist/server/wait-subscription-scan.js +46 -1
  90. package/dist/server/workspace-snapshot.js +60 -11
  91. package/extensions/webui.ts +90 -24
  92. package/package.json +5 -3
  93. package/plugin-sdk/README.md +25 -4
  94. package/plugin-sdk/import-check.mjs +210 -0
  95. package/plugin-sdk/index.d.ts +21 -1
  96. package/plugin-sdk/index.mjs +6 -0
  97. package/plugins/catalog.json +53 -2
  98. package/themes/aetheris.css +3 -1
  99. package/themes/translucent.css +8 -1
  100. package/themes/transparent.css +9 -1
  101. package/themes/zhupi-dark.css +1 -1
  102. package/themes/zhupi.css +1 -1
  103. package/web/dist/assets/{TerminalPanel-NerrJlTS.js → TerminalPanel-DD7I5_aC.js} +2 -2
  104. package/web/dist/assets/index-CpjA1YdT.css +1 -0
  105. package/web/dist/assets/index-nKn87VuM.js +678 -0
  106. package/web/dist/index.html +2 -2
  107. package/web/dist/sw.js +1 -1
  108. package/web/dist/assets/index-BdMaGCcs.css +0 -1
  109. package/web/dist/assets/index-ByCBN4Kt.js +0 -368
@@ -0,0 +1,96 @@
1
+ /**
2
+ * plan_update customTool:结构化任务执行计划更新工具(Plan Mode / Step State Machine)。
3
+ *
4
+ * 跟踪决策就绪步骤、文件改动清单(File Touch List)与状态机流转。
5
+ * 从 agent-service.ts 抽出为独立模块。
6
+ */
7
+ import { Type } from "typebox";
8
+ import { PLAN_UPDATE_TOOL_NAME } from "./tool-manager.js";
9
+ /**
10
+ * 将 SoL-Pi 的 update_plan 步骤结构({ id, goal, status })标准化为 pi-web-ui 的 PlanStep[] 结构。
11
+ */
12
+ export function normalizeSolPlanToPlanSteps(steps) {
13
+ if (!Array.isArray(steps))
14
+ return { steps: [] };
15
+ let activeStepId = null;
16
+ const normalizedSteps = steps.map((s, idx) => {
17
+ const step = (s && typeof s === "object" ? s : {});
18
+ const id = typeof step.id === "string" && step.id ? step.id : String(idx + 1);
19
+ const rawTitle = typeof step.goal === "string" ? step.goal : typeof step.title === "string" ? step.title : `Step ${id}`;
20
+ const rawStatus = typeof step.status === "string" ? step.status : "pending";
21
+ let status = "pending";
22
+ if (rawStatus === "completed" || rawStatus === "done") {
23
+ status = "done";
24
+ }
25
+ else if (rawStatus === "in_progress") {
26
+ status = "in_progress";
27
+ if (!activeStepId)
28
+ activeStepId = id;
29
+ }
30
+ else if (rawStatus === "failed") {
31
+ status = "failed";
32
+ }
33
+ const description = typeof step.description === "string" ? step.description : undefined;
34
+ return { id, title: rawTitle, status, ...(description ? { description } : {}) };
35
+ });
36
+ return { steps: normalizedSteps, activeStepId };
37
+ }
38
+ /**
39
+ * 结构化任务执行计划更新工具(plan_update)— Plan Mode / Step State Machine。
40
+ */
41
+ export function makePlanUpdateTool(planManager, getActiveConvTarget, emit, flushSnapshot, onPersist) {
42
+ return {
43
+ name: PLAN_UPDATE_TOOL_NAME,
44
+ label: "plan_update",
45
+ description: "Update the structured task plan / step state machine (Plan Mode) and track progress (pending -> in_progress -> done/failed).",
46
+ promptSnippet: "track decision-ready steps, file touch list, and live status",
47
+ promptGuidelines: [
48
+ "Use plan_update early on non-trivial tasks to outline decision-ready steps before coding",
49
+ "Per step: discovery conclusions, files to be touched (File Touch List), rollback strategy",
50
+ "Update step status as work progresses for real-time visibility",
51
+ ],
52
+ parameters: Type.Object({
53
+ steps: Type.Array(Type.Object({
54
+ id: Type.String({ description: "Unique step ID, e.g. '1', 'step-1'" }),
55
+ title: Type.String({ description: "Short step title" }),
56
+ status: Type.Optional(Type.Unsafe({
57
+ type: "string",
58
+ enum: ["pending", "in_progress", "done", "failed"],
59
+ description: "Step status: pending | in_progress | done | failed (default: pending)",
60
+ })),
61
+ description: Type.Optional(Type.String({
62
+ description: "Optional step detail: acceptance criteria, files touched, rollback note.",
63
+ })),
64
+ }), { description: "List of plan steps" }),
65
+ activeStepId: Type.Optional(Type.String({ description: "ID of the step currently being executed" })),
66
+ }),
67
+ execute: async (toolCallId, params) => {
68
+ const target = getActiveConvTarget();
69
+ const convId = typeof target === "string" ? target : target.id;
70
+ const sessionId = typeof target === "string" ? undefined : target.sessionId;
71
+ const p = params;
72
+ const plan = planManager.setPlan(convId, p.steps, p.activeStepId, sessionId);
73
+ if (typeof target !== "string" && target.sessionManager) {
74
+ try {
75
+ const sm = target.sessionManager;
76
+ sm?.appendCustomEntry?.("plan/update", { plan });
77
+ }
78
+ catch {
79
+ // 转录追加失败不影响主流程
80
+ }
81
+ }
82
+ onPersist?.(convId, plan);
83
+ emit({
84
+ type: "plan_updated",
85
+ conversationId: convId,
86
+ plan,
87
+ });
88
+ flushSnapshot();
89
+ const summary = planManager.describePlan(convId);
90
+ return {
91
+ content: [{ type: "text", text: `Plan updated successfully.\n\n${summary}` }],
92
+ details: { plan },
93
+ };
94
+ },
95
+ };
96
+ }
@@ -11,9 +11,18 @@ export const SLOT_EXAMPLES = {
11
11
  "contextmenu.topbar": `{ "ui": { "contextmenu.topbar": [{ "id": "m", "label": "顶栏菜单", "kind": "action", "action": "my:m" }] } }`,
12
12
  "contextmenu.message": `{ "ui": { "contextmenu.message": [{ "id": "m", "label": "消息菜单", "kind": "action", "action": "my:m" }] } }`,
13
13
  "contextmenu.session": `{ "ui": { "contextmenu.session": [{ "id": "m", "label": "会话菜单", "kind": "action", "action": "my:m" }] } }`,
14
+ "contextmenu.project": `{ "ui": { "contextmenu.project": [{ "id": "m", "label": "项目菜单", "kind": "action", "action": "my:m" }] } }`,
14
15
  "contextmenu.file": `{ "contextmenu.file": [{ "id": "mail", "label": "发到邮箱", "kind": "action", "action": "my:send" }] }`,
15
16
  "contextmenu.toolcall": `{ "ui": { "contextmenu.toolcall": [{ "id": "m", "label": "工具菜单", "kind": "action", "action": "my:m" }] } }`,
16
17
  "settings.pages": `{ "settings": [{ "id": "conf", "label": "邮箱设置", "kind": "page" }] }`,
18
+ "tasks.panel": `{ "ui": { "tasks.panel": [{ "id": "pm2", "label": "pm2 托管的应用", "kind": "view" }] } }`,
19
+ "leftpanel.projects.actions": `{ "ui": { "leftpanel.projects.actions": [{ "id": "m", "label": "项目标题按钮", "kind": "action", "action": "my:m" }] } }`,
20
+ "leftpanel.project": `{ "ui": { "leftpanel.project": [{ "id": "m", "label": "项目行", "kind": "action", "action": "my:m" }] } }`,
21
+ "leftpanel.running.actions": `{ "ui": { "leftpanel.running.actions": [{ "id": "m", "label": "运行标题按钮", "kind": "action", "action": "my:m" }] } }`,
22
+ "leftpanel.history.actions": `{ "ui": { "leftpanel.history.actions": [{ "id": "m", "label": "历史标题按钮", "kind": "action", "action": "my:m" }] } }`,
23
+ "leftpanel.sections": `{ "ui": { "leftpanel.sections": [{ "id": "m", "label": "我的分区", "kind": "view" }] } }`,
24
+ "leftpanel.running": `{ "ui": { "leftpanel.running": [{ "id": "m", "label": "运行行", "kind": "action", "action": "my:m" }] } }`,
25
+ "leftpanel.history": `{ "ui": { "leftpanel.history": [{ "id": "m", "label": "历史行", "kind": "action", "action": "my:m" }] } }`,
17
26
  "leftpanel.sessions": `{ "ui": { "leftpanel.sessions": [{ "id": "m", "label": "会话区", "kind": "action", "action": "my:m" }] } }`,
18
27
  "chat.header": `{ "ui": { "chat.header": [{ "id": "m", "label": "会话题头", "kind": "action", "action": "my:m" }] } }`,
19
28
  "chat.empty": `{ "ui": { "chat.empty": [{ "id": "m", "label": "空态", "kind": "action", "action": "my:m" }] } }`,
@@ -29,6 +38,18 @@ export const SLOT_EXAMPLES = {
29
38
  /** 宿主方法表(与 server/plugins.ts#PluginHost 同语义的精简版:只收发现用的注册/调用面)。
30
39
  * needs="-" = 观察/基础设施类(无需能力声明);其余走 can() 门控。 */
31
40
  export const HOST_METHODS = [
41
+ {
42
+ name: "leftPanel.setRunning",
43
+ needs: "ui",
44
+ summary: "左栏「运行的对话」登记插件运行条目(整体替换即心跳;ttlMs 缺省 60s 无心跳自动清空)",
45
+ example: `host.leftPanel.setRunning([{ id: "sync-1", title: "同步邮件", status: "running", hint: "3/10" }])`,
46
+ },
47
+ {
48
+ name: "leftPanel.clear",
49
+ needs: "ui",
50
+ summary: "立即清空本插件在左栏的运行条目",
51
+ example: `host.leftPanel.clear()`,
52
+ },
32
53
  {
33
54
  name: "ui.register",
34
55
  needs: "ui",
@@ -69,7 +90,7 @@ export const HOST_METHODS = [
69
90
  name: "registerAgentTool",
70
91
  needs: "tools",
71
92
  summary: "给 AI 注册工具(插件给模型加能力,与 AI 写插件方向相反)",
72
- example: `host.registerAgentTool({ name: "mail_list", description: "…", execute: async () => ({}) })`,
93
+ example: `host.registerAgentTool({ name: "mail", description: "…", execute: async () => ({}) })`,
73
94
  },
74
95
  {
75
96
  name: "onToolPre",
@@ -176,8 +197,8 @@ export const HOST_METHODS = [
176
197
  {
177
198
  name: "getActiveConversation",
178
199
  needs: "-",
179
- summary: "读当前打开对话快照(只读引用,广播前抽摘要)",
180
- example: `host.getActiveConversation()`,
200
+ summary: "读对话快照:{clientId} 取该标签页正在看的对话,缺省=最近活跃的非子代理会话",
201
+ example: `host.getActiveConversation({ clientId })`,
181
202
  },
182
203
  {
183
204
  name: "onConversationChanged",
@@ -185,6 +206,12 @@ export const HOST_METHODS = [
185
206
  summary: "订阅切对话(轨迹插件重拉时间线)",
186
207
  example: `host.onConversationChanged(() => {})`,
187
208
  },
209
+ {
210
+ name: "onClientModelChanged",
211
+ needs: "-",
212
+ summary: "订阅模型切换成功(回调带 clientId/对话/model;失败与重复不发)",
213
+ example: `host.onClientModelChanged((snap) => {})`,
214
+ },
188
215
  {
189
216
  name: "storage",
190
217
  needs: "-",
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 插件会话快照的「选哪个会话」策略(issue #542,纯函数,零宿主/零 SDK 依赖)。
3
+ *
4
+ * 背景:`host.getActiveConversation()` 原来只认「全局 lastActiveAt 最大者」,
5
+ * 于是两个标签页各看一个对话时,插件读到的是另一个标签页的会话;子代理跑起来
6
+ * 比用户正在看的对话还勤,也会把父对话挤出快照。这里把选会话的两条口径拆成
7
+ * 纯函数,让 agent-service 只负责取数据、这里负责判定(可单测)。
8
+ *
9
+ * 另外附一个模型变更事件去重键:`host.onClientModelChanged` 只在模型真的换了
10
+ * 的时候发一次(重复点同一个模型、重连重放 set_model 都不该重复触发订阅者)。
11
+ */
12
+ /** 单客户端内选会话:给了 `active` 就优先认它(= 该标签页正在看的对话),
13
+ * 否则退回归属本客户端的「最近活跃」会话;`includeSubagents=false`(缺省)时
14
+ * 跳过子代理对话。找不到任何符合条件的会话 → null(调用方据此回落)。
15
+ *
16
+ * `conversations` 只遍历一遍(Map.values() 直传,不额外建数组)。 */
17
+ export function pickClientConversation(conversations, opts = {}) {
18
+ const include = opts.includeSubagents === true;
19
+ const active = opts.active;
20
+ if (active && (include || !active.isSubagent))
21
+ return active;
22
+ let best = null;
23
+ for (const c of conversations) {
24
+ if (!include && c.isSubagent)
25
+ continue;
26
+ if (!best || c.lastActiveAt > best.lastActiveAt)
27
+ best = c;
28
+ }
29
+ return best;
30
+ }
31
+ /** 跨客户端回落:最近活跃的**非子代理**会话(`at` 最大者)。
32
+ * 缺省语义(不传 clientId / clientId 不认识)走这条 —— 与 #542 之前的行为
33
+ * 一致,只多一条「子代理不算数」。 */
34
+ export function pickLatestClientSnapshot(snapshots) {
35
+ let best = null;
36
+ for (const s of snapshots) {
37
+ if (!s || s.isSubagent)
38
+ continue;
39
+ if (!best || s.at > best.at)
40
+ best = s;
41
+ }
42
+ return best;
43
+ }
44
+ /** 模型变更事件的去重键:同一客户端、同一对话、同一模型 = 同一件事。 */
45
+ export function modelChangeKey(snap) {
46
+ return `${snap.clientId}\u0000${snap.conversationId}\u0000${snap.model ?? ""}`;
47
+ }
@@ -370,9 +370,19 @@ export function ensurePluginDeps(pluginDir, specs, onProgress) {
370
370
  catch { }
371
371
  }
372
372
  onProgress?.(`正在安装依赖:${missing.join(", ")}…(首次约需几分钟)`);
373
- // win32 的 npm 是 .cmd——spawnSync 直接跑会被 EINVAL 拒绝,必须走 shell;
374
- // posix 不用 shell(路径不含空格假设成立,与宿主其它 spawn 一致)。
375
- const res = spawnSync(process.platform === "win32" ? "npm.cmd" : "npm", ["install", "--no-audit", "--no-fund", ...missing], { cwd: pluginDir, timeout: DEP_TIMEOUT_MS, shell: process.platform === "win32", encoding: "utf8" });
373
+ // win32 的 npm 是 .cmd——spawnSync 直接跑会被 EINVAL 拒绝;走 cmd.exe /d /s /c
374
+ // 规避 DEP0190 与命令行注入,posix 不用 shell(路径不含空格假设成立,与宿主其它 spawn 一致)。
375
+ const isWin = process.platform === "win32";
376
+ const spawnCmd = isWin ? process.env.ComSpec || "cmd.exe" : "npm";
377
+ const spawnArgs = isWin
378
+ ? ["/d", "/s", "/c", "npm.cmd", "install", "--no-audit", "--no-fund", ...missing]
379
+ : ["install", "--no-audit", "--no-fund", ...missing];
380
+ const res = spawnSync(spawnCmd, spawnArgs, {
381
+ cwd: pluginDir,
382
+ timeout: DEP_TIMEOUT_MS,
383
+ windowsHide: true,
384
+ encoding: "utf8",
385
+ });
376
386
  if (res.error || res.status !== 0) {
377
387
  console.error(`[plugin-deps] ${join(pluginDir)} npm install 失败:`, res.error ?? res.stderr?.slice(0, 500));
378
388
  return false;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * UI_SLOTS — 宿主支持的全部挂载点集合,用于运行态校验。
3
+ * 抽离到独立文件以打破 client-state.ts 与 plugins.ts 之间的循环依赖。
4
+ */
5
+ export const UI_SLOTS = new Set([
6
+ "topbar.primary",
7
+ "topbar.overflow",
8
+ "bottombar",
9
+ "composer.leading",
10
+ "composer.actions",
11
+ "message.actions",
12
+ "rightpanel.tabs",
13
+ "contextmenu.topbar",
14
+ "contextmenu.message",
15
+ "contextmenu.session",
16
+ "contextmenu.project",
17
+ "contextmenu.file",
18
+ "contextmenu.toolcall",
19
+ "settings.pages",
20
+ "tasks.panel",
21
+ "leftpanel.projects.actions",
22
+ "leftpanel.project",
23
+ "leftpanel.running.actions",
24
+ "leftpanel.history.actions",
25
+ "leftpanel.running",
26
+ "leftpanel.sections",
27
+ "leftpanel.history",
28
+ "leftpanel.sessions",
29
+ "chat.header",
30
+ "chat.empty",
31
+ "file.preview.toolbar",
32
+ "terminal.toolbar",
33
+ "scm.toolbar",
34
+ "goalbar.actions",
35
+ "notice.actions",
36
+ "modal.dialog",
37
+ "sidebar.left",
38
+ "sidebar.right",
39
+ ]);