pi-web-ui 0.100.0 → 0.102.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.
- package/CHANGELOG.md +53 -1
- package/README.md +46 -44
- package/README.zh-CN.md +41 -39
- package/bin/pi-web-ui.mjs +17 -19
- package/dist/server/agent-formatters.js +191 -0
- package/dist/server/agent-service-daemon.js +1266 -0
- package/dist/server/agent-service.js +9884 -12815
- package/dist/server/approval-default-rules.js +158 -0
- package/dist/server/approval-rules.js +41 -167
- package/dist/server/ask-user-question-tool.js +104 -0
- package/dist/server/attachment-store.js +38 -1
- package/dist/server/bash-tool.js +83 -0
- package/dist/server/browser-page-tool.js +207 -0
- package/dist/server/client-id-utils.js +51 -0
- package/dist/server/client-state.js +38 -2
- package/dist/server/compaction-markers.js +34 -1
- package/dist/server/context-budget-runner.js +43 -0
- package/dist/server/dangling-tools.js +18 -5
- package/dist/server/delegate-mode.js +1 -0
- package/dist/server/dispatch-domain-handlers.js +631 -0
- package/dist/server/dispatch-plugin-handlers.js +300 -0
- package/dist/server/dsh/dsh-agent-service.js +30 -5
- package/dist/server/dsh/runtime/goal-rpc.mjs +5 -1
- package/dist/server/goal-evidence.js +9 -2
- package/dist/server/goal-service.js +1 -1
- package/dist/server/hashline-engine.js +1 -1
- package/dist/server/index.js +191 -969
- package/dist/server/left-panel-running.js +115 -0
- package/dist/server/lsp-tool.js +40 -12
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/market-service.js +277 -0
- package/dist/server/mcp-bridge.js +137 -30
- package/dist/server/mcp-hot-reload.js +84 -27
- package/dist/server/mcp-manager.js +215 -0
- package/dist/server/message-entry-resolver.js +32 -0
- package/dist/server/orphan-manager.js +44 -0
- package/dist/server/persona-chain.js +63 -0
- package/dist/server/plan-mode.js +2 -0
- package/dist/server/plan-update-tool.js +96 -0
- package/dist/server/plugin-api-catalog.js +20 -0
- package/dist/server/plugin-facilities.js +13 -3
- package/dist/server/plugin-installer.js +6 -1
- package/dist/server/plugin-ui-slots.js +39 -0
- package/dist/server/plugins.js +72 -38
- package/dist/server/preset-fields.js +35 -0
- package/dist/server/preset-share.js +9 -0
- package/dist/server/process-utils.js +30 -0
- package/dist/server/prompt-assembler.js +80 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/scm-commitmsg.js +74 -0
- package/dist/server/serialize.js +97 -7
- package/dist/server/session-branch.js +367 -0
- package/dist/server/session-parser.js +235 -0
- package/dist/server/session-search.js +158 -0
- package/dist/server/settings-service.js +28 -1
- package/dist/server/skill-content-filler.js +33 -0
- package/dist/server/subagent-handoff.js +18 -0
- package/dist/server/subagent-helpers.js +88 -0
- package/dist/server/terminals.js +155 -58
- package/dist/server/tool-guards.js +527 -0
- package/dist/server/tool-host-factories.js +217 -0
- package/dist/server/tool-manager.js +30 -5
- package/dist/server/wait-subscription-scan.js +46 -1
- package/dist/server/workspace-snapshot.js +18 -0
- package/extensions/webui.ts +90 -24
- package/package.json +1 -1
- package/plugin-sdk/README.md +17 -0
- package/plugin-sdk/index.d.ts +17 -0
- package/plugin-sdk/index.mjs +5 -0
- package/plugins/catalog.json +20 -0
- package/themes/aetheris.css +3 -1
- package/themes/translucent.css +8 -1
- package/themes/transparent.css +9 -1
- package/themes/zhupi-dark.css +3 -14
- package/themes/zhupi.css +2 -16
- package/web/dist/assets/{TerminalPanel-C3I1Mc-C.js → TerminalPanel-CYGOzbPT.js} +1 -1
- package/web/dist/assets/index-CP71PHb6.js +680 -0
- package/web/dist/assets/index-ytRwL6j0.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-B-E2EM_0.css +0 -1
- package/web/dist/assets/index-BYumAaGi.js +0 -379
package/bin/pi-web-ui.mjs
CHANGED
|
@@ -913,7 +913,7 @@ if [ -n "\${SERVER_PID:-}" ]; then wait "$SERVER_PID"; fi
|
|
|
913
913
|
}
|
|
914
914
|
|
|
915
915
|
function installLinuxShortcut(opts) {
|
|
916
|
-
const { name, port
|
|
916
|
+
const { name, port } = serviceOptions(opts);
|
|
917
917
|
const url = `http://localhost:${port}`;
|
|
918
918
|
const scriptDir = join(homedir(), ".local", "share", "pi-web-ui");
|
|
919
919
|
const scriptPath = join(scriptDir, `${name}-start.sh`);
|
|
@@ -2355,8 +2355,8 @@ async function installOnePlugin({ rawSpec, name, force, build, noBuild, dataDir,
|
|
|
2355
2355
|
);
|
|
2356
2356
|
const target = join(pluginsDir, id);
|
|
2357
2357
|
let backupTs = null;
|
|
2358
|
-
|
|
2359
|
-
const
|
|
2358
|
+
const PRESERVED_FILES = ["config.json", "secrets.bin", "storage.json"];
|
|
2359
|
+
const preservedData = new Map();
|
|
2360
2360
|
if (existsSync(target)) {
|
|
2361
2361
|
if (!force)
|
|
2362
2362
|
throw new Error(
|
|
@@ -2367,11 +2367,13 @@ async function installOnePlugin({ rawSpec, name, force, build, noBuild, dataDir,
|
|
|
2367
2367
|
// 更新前备份旧版本(<dataDir>/plugin-backups/<id>-<ts>/,保留最近 3 份),
|
|
2368
2368
|
// 失败时自动回滚。备份与安装同 filter:不带 .git/node_modules。
|
|
2369
2369
|
backupTs = ensurePluginBackup(dataDir, id, { source: rawSpec });
|
|
2370
|
-
//
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2370
|
+
// 插件凭据/加密机密/私有存储不因升级丢失:先取出旧 config.json / secrets.bin / storage.json,拷完新文件后原样放回
|
|
2371
|
+
for (const fname of PRESERVED_FILES) {
|
|
2372
|
+
try {
|
|
2373
|
+
preservedData.set(fname, readFileSync(join(target, fname)));
|
|
2374
|
+
} catch {
|
|
2375
|
+
/* 无该文件 */
|
|
2376
|
+
}
|
|
2375
2377
|
}
|
|
2376
2378
|
rmSync(target, { recursive: true, force: true });
|
|
2377
2379
|
}
|
|
@@ -2393,8 +2395,10 @@ async function installOnePlugin({ rawSpec, name, force, build, noBuild, dataDir,
|
|
|
2393
2395
|
: `Plugin update failed: ${err?.message ?? err}\n (no backup available, re-run install --force)`,
|
|
2394
2396
|
);
|
|
2395
2397
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
+
for (const [fname, buf] of preservedData) {
|
|
2399
|
+
if (!existsSync(join(target, fname))) {
|
|
2400
|
+
writeFileSync(join(target, fname), buf);
|
|
2401
|
+
}
|
|
2398
2402
|
}
|
|
2399
2403
|
// 记录安装来源:设置面板「更新」按钮据此重跑同一条安装命令(--force 覆盖)。
|
|
2400
2404
|
try {
|
|
@@ -2666,12 +2670,6 @@ function pluginSdkSources() {
|
|
|
2666
2670
|
return files;
|
|
2667
2671
|
}
|
|
2668
2672
|
|
|
2669
|
-
/** 包内 plugin-sdk 入口(版本号读取用)。 */
|
|
2670
|
-
function pluginSdkSource() {
|
|
2671
|
-
return pluginSdkSources()?.find((f) => f.name === "index.mjs")?.src;
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
/** 把整份 SDK 拷进某目录(`<plugin>/sdk` 服务端用;`<plugin>/client/sdk` 客户端用)。 */
|
|
2675
2673
|
function copySdkInto(dir, sources) {
|
|
2676
2674
|
mkdirSync(dir, { recursive: true });
|
|
2677
2675
|
for (const { name, src } of sources) copyFileSync(src, join(dir, name));
|
|
@@ -2883,12 +2881,12 @@ function buildPluginScaffold(id, template, useSdk, withTest = false) {
|
|
|
2883
2881
|
`\n` +
|
|
2884
2882
|
`- \`manifest.json\` —— 插件声明(id/name/version/description/apiVersion/permissions…;apiVersion 2 必须写 permissions,零能力写 \`[]\`)\n` +
|
|
2885
2883
|
`- \`index.mjs\` —— 服务端入口(\`export default { activate(host) }\`)\n` +
|
|
2886
|
-
`- \`client/entry.mjs\` —— 客户端视图${template === "renderer" ? "
|
|
2884
|
+
`- \`client/entry.mjs\` —— 客户端视图${template === "renderer" ? "(渲染器:`{ renderers }`)" : "(`{ mount }`)"}\n` +
|
|
2887
2885
|
(useSdk
|
|
2888
2886
|
? `- \`sdk/index.mjs\` + \`sdk/client-utils.mjs\` —— plugin-sdk 拷贝(服务端用:definePlugin/defineView/onUiAction)\n`
|
|
2889
2887
|
: "") +
|
|
2890
2888
|
(useSdk && templateClientUsesSdk(template)
|
|
2891
|
-
? `- \`client/sdk/\` —— 同一份 SDK 的**客户端**拷贝:宿主只暴露 \`/plugins/<id>/client/*\`,客户端依赖必须落在 \`client/\` 内(\`client/entry.mjs\` 只能 \`import
|
|
2889
|
+
? `- \`client/sdk/\` —— 同一份 SDK 的**客户端**拷贝:宿主只暴露 \`/plugins/<id>/client/*\`,客户端依赖必须落在 \`client/\` 内(\`client/entry.mjs\` 只能 \`import "./sdk/index.mjs"\`)\n`
|
|
2892
2890
|
: "") +
|
|
2893
2891
|
(withTest && useSdk
|
|
2894
2892
|
? "- `index.test.mjs` —— 最小单测(`node --test index.test.mjs`,createMockHost harness)\n"
|
|
@@ -3362,7 +3360,7 @@ function pluginUninstallCmd(argv) {
|
|
|
3362
3360
|
}
|
|
3363
3361
|
|
|
3364
3362
|
function pluginListCmd(argv) {
|
|
3365
|
-
const { opts
|
|
3363
|
+
const { opts } = parseFlags(argv);
|
|
3366
3364
|
if (opts.help) {
|
|
3367
3365
|
console.log(PLUGIN_HELP);
|
|
3368
3366
|
return;
|
|
@@ -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
|
+
}
|