pi-web-ui 0.100.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 (77) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/README.md +46 -44
  3. package/README.zh-CN.md +41 -39
  4. package/bin/pi-web-ui.mjs +4 -10
  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 +9883 -12935
  8. package/dist/server/approval-default-rules.js +158 -0
  9. package/dist/server/approval-rules.js +41 -167
  10. package/dist/server/ask-user-question-tool.js +94 -0
  11. package/dist/server/attachment-store.js +38 -1
  12. package/dist/server/bash-tool.js +83 -0
  13. package/dist/server/browser-page-tool.js +207 -0
  14. package/dist/server/client-id-utils.js +51 -0
  15. package/dist/server/client-state.js +23 -2
  16. package/dist/server/compaction-markers.js +34 -1
  17. package/dist/server/context-budget-runner.js +43 -0
  18. package/dist/server/dangling-tools.js +18 -5
  19. package/dist/server/delegate-mode.js +1 -0
  20. package/dist/server/dispatch-domain-handlers.js +631 -0
  21. package/dist/server/dispatch-plugin-handlers.js +300 -0
  22. package/dist/server/dsh/dsh-agent-service.js +9 -1
  23. package/dist/server/goal-evidence.js +9 -2
  24. package/dist/server/goal-service.js +1 -1
  25. package/dist/server/hashline-engine.js +1 -1
  26. package/dist/server/index.js +191 -969
  27. package/dist/server/left-panel-running.js +115 -0
  28. package/dist/server/lsp-tool.js +40 -12
  29. package/dist/server/markers-list-tool.js +34 -0
  30. package/dist/server/market-service.js +277 -0
  31. package/dist/server/mcp-bridge.js +137 -30
  32. package/dist/server/mcp-hot-reload.js +84 -27
  33. package/dist/server/mcp-manager.js +215 -0
  34. package/dist/server/message-entry-resolver.js +32 -0
  35. package/dist/server/orphan-manager.js +44 -0
  36. package/dist/server/persona-chain.js +63 -0
  37. package/dist/server/plan-mode.js +2 -0
  38. package/dist/server/plan-update-tool.js +96 -0
  39. package/dist/server/plugin-api-catalog.js +20 -0
  40. package/dist/server/plugin-facilities.js +13 -3
  41. package/dist/server/plugin-ui-slots.js +39 -0
  42. package/dist/server/plugins.js +71 -38
  43. package/dist/server/preset-fields.js +7 -0
  44. package/dist/server/preset-share.js +1 -0
  45. package/dist/server/process-utils.js +30 -0
  46. package/dist/server/prompt-assembler.js +80 -0
  47. package/dist/server/scm-commitmsg.js +74 -0
  48. package/dist/server/serialize.js +97 -7
  49. package/dist/server/session-branch.js +367 -0
  50. package/dist/server/session-parser.js +235 -0
  51. package/dist/server/session-search.js +158 -0
  52. package/dist/server/settings-service.js +13 -1
  53. package/dist/server/skill-content-filler.js +33 -0
  54. package/dist/server/subagent-handoff.js +18 -0
  55. package/dist/server/subagent-helpers.js +88 -0
  56. package/dist/server/terminals.js +155 -58
  57. package/dist/server/tool-guards.js +527 -0
  58. package/dist/server/tool-host-factories.js +217 -0
  59. package/dist/server/tool-manager.js +30 -5
  60. package/dist/server/wait-subscription-scan.js +46 -1
  61. package/dist/server/workspace-snapshot.js +18 -0
  62. package/extensions/webui.ts +90 -24
  63. package/package.json +1 -1
  64. package/plugin-sdk/README.md +17 -0
  65. package/plugin-sdk/index.d.ts +17 -0
  66. package/plugin-sdk/index.mjs +5 -0
  67. package/plugins/catalog.json +20 -0
  68. package/themes/aetheris.css +3 -1
  69. package/themes/translucent.css +8 -1
  70. package/themes/transparent.css +9 -1
  71. package/web/dist/assets/{TerminalPanel-C3I1Mc-C.js → TerminalPanel-DD7I5_aC.js} +1 -1
  72. package/web/dist/assets/index-CpjA1YdT.css +1 -0
  73. package/web/dist/assets/index-nKn87VuM.js +678 -0
  74. package/web/dist/index.html +2 -2
  75. package/web/dist/sw.js +1 -1
  76. package/web/dist/assets/index-B-E2EM_0.css +0 -1
  77. package/web/dist/assets/index-BYumAaGi.js +0 -379
@@ -0,0 +1,191 @@
1
+ import { writeAtomicSync } from "./atomic-file.js";
2
+ /** 轨迹事件 payload 封顶(可直接广播/持久化,不撑爆 storage.json)。 */
3
+ export const RUN_TASK_CAP = 500;
4
+ export const RUN_ARGS_CAP = 4000;
5
+ export const RUN_RESULT_CAP = 4000;
6
+ /** Cap on simultaneously open NON-subagent conversations of ONE project */
7
+ export const MAX_OPEN_CONVERSATIONS = 8;
8
+ /** 同时存活的子代理上限(按客户端计,含嵌套派生的孙子辈)。 */
9
+ export const MAX_SUBAGENTS = 16;
10
+ /** SubagentSnapshot.prompt 下发上限:存的是全量 prompt,快照里只带前 N 字符。 */
11
+ export const SUBAGENT_PROMPT_SNAPSHOT_CAP = 2000;
12
+ export const DEFAULT_CONV_TITLE = "新对话";
13
+ export function truncRun(s, cap) {
14
+ return s.length <= cap ? s : `${s.slice(0, cap)}\n… [truncated]`;
15
+ }
16
+ /** 从 SDK tool result 里抠可读文本预览(text 块拼接,图片/二进制占位,封顶)。 */
17
+ export function previewToolResult(result) {
18
+ try {
19
+ const content = result?.content;
20
+ if (Array.isArray(content)) {
21
+ const parts = [];
22
+ for (const c of content) {
23
+ if (c && typeof c === "object" && c.type === "text") {
24
+ parts.push(String(c.text ?? ""));
25
+ }
26
+ else {
27
+ parts.push("[…]");
28
+ }
29
+ }
30
+ return truncRun(parts.join("\n"), RUN_RESULT_CAP);
31
+ }
32
+ if (typeof result === "string")
33
+ return truncRun(result, RUN_RESULT_CAP);
34
+ return truncRun(JSON.stringify(result ?? null), RUN_RESULT_CAP);
35
+ }
36
+ catch {
37
+ return "[unserializable result]";
38
+ }
39
+ }
40
+ /** 转录整文件重写的原子落盘:先写同目录临时文件再 rename。 */
41
+ export function atomicWriteFileSync(file, data) {
42
+ writeAtomicSync(file, data);
43
+ }
44
+ /** First user text in a session, truncated for the conversation list. */
45
+ export function conversationTitle(session) {
46
+ try {
47
+ const named = session.sessionManager.getSessionName();
48
+ if (named && named.trim())
49
+ return named.trim();
50
+ }
51
+ catch {
52
+ // best-effort — fall through to first-message title
53
+ }
54
+ try {
55
+ for (const m of session.agent.state.messages) {
56
+ if (m.role !== "user")
57
+ continue;
58
+ const content = m.content;
59
+ let text = "";
60
+ if (typeof content === "string") {
61
+ text = content;
62
+ }
63
+ else if (Array.isArray(content)) {
64
+ for (const p of content) {
65
+ if (p &&
66
+ typeof p === "object" &&
67
+ p.type === "text" &&
68
+ typeof p.text === "string") {
69
+ text = p.text;
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ const trimmed = text.trim().replace(/\s+/g, " ");
75
+ if (trimmed.length > 0) {
76
+ return trimmed.length > 30 ? `${trimmed.slice(0, 30)}…` : trimmed;
77
+ }
78
+ }
79
+ }
80
+ catch {
81
+ // best-effort
82
+ }
83
+ return DEFAULT_CONV_TITLE;
84
+ }
85
+ /**
86
+ * 插件结构化工具 → SDK ToolDefinition。
87
+ * execute 返回值宽容处理:{content,details} 原样收编;字符串/对象包成文本块。
88
+ */
89
+ export function pluginToolToDefinition(tool) {
90
+ const normalize = (result) => {
91
+ if (result && typeof result === "object" && Array.isArray(result.content)) {
92
+ return result;
93
+ }
94
+ const text = typeof result === "string" ? result : JSON.stringify(result ?? null, null, 2);
95
+ return { content: [{ type: "text", text }] };
96
+ };
97
+ return {
98
+ name: tool.name,
99
+ label: tool.label ?? tool.name,
100
+ description: tool.description,
101
+ promptSnippet: tool.promptSnippet,
102
+ promptGuidelines: tool.promptGuidelines,
103
+ parameters: (tool.parameters ?? {
104
+ type: "object",
105
+ properties: {},
106
+ }),
107
+ execute: async (toolCallId, params, signal, onUpdate) => {
108
+ const raw = await tool.execute(toolCallId, params, signal, onUpdate ? (partial) => onUpdate(normalize(partial)) : undefined);
109
+ return normalize(raw);
110
+ },
111
+ };
112
+ }
113
+ /**
114
+ * Cheap per-message discriminator for the serialization cache key. Persisted
115
+ * message content never changes, so this is stable across snapshots, while
116
+ * several same-role messages created within one millisecond (attachment
117
+ * asides) get distinct keys.
118
+ */
119
+ export function contentFingerprint(m) {
120
+ const summary = m.summary;
121
+ if (typeof summary === "string" && summary.length > 0) {
122
+ let h = 5381;
123
+ for (let i = 0; i < summary.length && i < 512; i++) {
124
+ h = ((h << 5) + h + summary.charCodeAt(i)) >>> 0;
125
+ }
126
+ return `sum:${h.toString(36)}:${summary.length}`;
127
+ }
128
+ const content = m.content;
129
+ if (!Array.isArray(content) || content.length === 0)
130
+ return "empty";
131
+ const first = content[0];
132
+ if (first?.type === "image") {
133
+ return `img:${(first.data ?? "").length}`;
134
+ }
135
+ const text = typeof first?.text === "string" ? first.text : "";
136
+ // djb2 — fast enough to run per snapshot, distinct enough for asides.
137
+ let h = 5381;
138
+ for (let i = 0; i < text.length && i < 512; i++) {
139
+ h = ((h << 5) + h + text.charCodeAt(i)) >>> 0;
140
+ }
141
+ return `txt:${h.toString(36)}:${text.length}`;
142
+ }
143
+ export function extractPartialText(partial) {
144
+ const content = partial?.content;
145
+ if (Array.isArray(content)) {
146
+ const text = content
147
+ .map((c) => (c?.type === "text" ? c.text : ""))
148
+ .join("");
149
+ return text.length > 0 ? text : null;
150
+ }
151
+ return null;
152
+ }
153
+ export function extractAssistantTextFromContent(content) {
154
+ if (typeof content === "string")
155
+ return content;
156
+ if (!Array.isArray(content))
157
+ return "";
158
+ return content
159
+ .filter((c) => c.type === "text" && typeof c.text === "string")
160
+ .map((c) => c.text)
161
+ .join("\n");
162
+ }
163
+ /** 描述首句(延迟加载目录里没 promptSnippet 时的回落摘要)。 */
164
+ export function firstSentence(description) {
165
+ const text = (description ?? "").trim();
166
+ if (!text)
167
+ return "";
168
+ const cut = text.split(/\n|[.。](?=\s|$)/)[0]?.trim() ?? "";
169
+ const head = cut || text;
170
+ return head.length > 160 ? `${head.slice(0, 160)}…` : head;
171
+ }
172
+ /** 会话当前模型的 "provider/id"(无模型时 null;软上限按模型覆盖用,issue #229)。 */
173
+ export function modelKeyOf(session) {
174
+ const m = session?.model;
175
+ if (!m || typeof m.provider !== "string" || typeof m.id !== "string")
176
+ return null;
177
+ return `${m.provider}/${m.id}`;
178
+ }
179
+ /** 会话当前模型的上下文窗口(未知时 0):live 统计优先,模型定义回落。 */
180
+ export function contextWindowOf(session) {
181
+ try {
182
+ const live = session?.getSessionStats?.()?.contextUsage?.contextWindow;
183
+ if (typeof live === "number" && live > 0)
184
+ return Math.floor(live);
185
+ }
186
+ catch {
187
+ // 会话未就绪 → 回落模型定义。
188
+ }
189
+ const def = session?.model?.contextWindow;
190
+ return typeof def === "number" && def > 0 ? Math.floor(def) : 0;
191
+ }