pi-web-ui 0.98.0 → 0.100.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 +85 -5
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/bin/pi-web-ui.mjs +174 -36
- package/dist/server/agent-service.js +1169 -152
- package/dist/server/approval-rules.js +95 -23
- package/dist/server/attachments.js +55 -0
- package/dist/server/bg-servers.js +82 -2
- package/dist/server/claim-files-tool.js +4 -4
- package/dist/server/client-state.js +41 -0
- package/dist/server/compact-context-tool.js +10 -9
- package/dist/server/conversation-read-tool.js +7 -8
- package/dist/server/conversation-touches.js +19 -0
- package/dist/server/delegate-task.js +10 -14
- package/dist/server/dsh/dsh-agent-service.js +116 -12
- package/dist/server/edit-soft-tool.js +10 -12
- package/dist/server/eval-tool.js +26 -6
- package/dist/server/goal-evidence.js +173 -0
- package/dist/server/goal-service.js +78 -15
- package/dist/server/hashline-engine.js +198 -31
- package/dist/server/index.js +55 -9
- package/dist/server/load-tools-tool.js +100 -0
- package/dist/server/lsp-tool.js +10 -16
- package/dist/server/marker-service.js +53 -12
- package/dist/server/markers/builtins/action.js +108 -0
- package/dist/server/markers/index.js +4 -1
- package/dist/server/model-enrich.js +2 -0
- package/dist/server/patch-remote-catalog.js +28 -10
- package/dist/server/patch-tool.js +74 -38
- package/dist/server/plan-manager.js +71 -30
- package/dist/server/plan-mode.js +7 -6
- package/dist/server/plugin-api-catalog.js +10 -3
- package/dist/server/plugin-conversation-view.js +47 -0
- package/dist/server/plugins.js +113 -26
- package/dist/server/present-files-tool.js +10 -11
- package/dist/server/preset-fields.js +693 -0
- package/dist/server/preset-share.js +1178 -0
- package/dist/server/prompt-composer.js +23 -9
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/read-tool.js +8 -10
- package/dist/server/resolve-global-sdk.js +80 -18
- package/dist/server/schedule-agent-tool.js +147 -146
- package/dist/server/sdk-origin.js +125 -37
- package/dist/server/settings-service.js +103 -84
- package/dist/server/skill-tool.js +3 -4
- package/dist/server/subagents.js +15 -22
- package/dist/server/terminals.js +29 -39
- package/dist/server/tool-approval.js +3 -1
- package/dist/server/tool-manager.js +63 -27
- package/dist/server/tool-prompt-overrides.js +158 -0
- package/dist/server/tool-prompts.js +42 -0
- package/dist/server/tool-signature.js +104 -0
- package/dist/server/update-check.js +0 -15
- package/dist/server/workspace-snapshot.js +42 -11
- package/package.json +5 -3
- package/plugin-sdk/README.md +8 -4
- package/plugin-sdk/import-check.mjs +210 -0
- package/plugin-sdk/index.d.ts +4 -1
- package/plugin-sdk/index.mjs +1 -0
- package/plugins/catalog.json +33 -2
- package/themes/zhupi-dark.css +1 -1
- package/themes/zhupi.css +1 -1
- package/web/dist/assets/{TerminalPanel-C88r3r3Q.js → TerminalPanel-C3I1Mc-C.js} +2 -2
- package/web/dist/assets/index-B-E2EM_0.css +1 -0
- package/web/dist/assets/index-BYumAaGi.js +379 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-2jDtjHvW.css +0 -1
- package/web/dist/assets/index-BjdK7s1M.js +0 -368
package/dist/server/index.js
CHANGED
|
@@ -1373,8 +1373,10 @@ service.onRunEvent = (ev) => pluginMgr.emitRunEvent(ev);
|
|
|
1373
1373
|
// 插件扩展点:对话切换通知(轨迹视图切会话后即重拉;dsh 引擎暂无)。
|
|
1374
1374
|
service.onConversationChanged = () => pluginMgr.emitConversationChanged();
|
|
1375
1375
|
// 插件扩展点:当前打开对话的快照(轨迹视图直接显示打开对话的时间线;
|
|
1376
|
-
// dsh 引擎无此方法时回退 null
|
|
1377
|
-
pluginMgr.conversationProvider = () => service.readConversationForPlugins?.() ?? null;
|
|
1376
|
+
// dsh 引擎无此方法时回退 null,插件显示空态)。#542:透传 {clientId} 选本标签页的对话。
|
|
1377
|
+
pluginMgr.conversationProvider = (opts) => service.readConversationForPlugins?.(opts) ?? null;
|
|
1378
|
+
// 插件扩展点:模型切换成功事件(#542;dsh 引擎无此钩子 = 不发事件)。
|
|
1379
|
+
service.onClientModelChanged = (snap) => pluginMgr.emitClientModelChanged(snap);
|
|
1378
1380
|
// 插件扩展点:无头调用 agent(微信通道等经 host.chat 投递外部消息,无浏览器也能跑)。
|
|
1379
1381
|
pluginMgr.chatProvider = (pluginId, req) => service.chatFromPlugin?.(pluginId, req) ?? Promise.reject(new Error("当前引擎不支持无头调用(仅标准 pi 引擎)"));
|
|
1380
1382
|
// 插件扩展点:插件注册的 AI 工具(registerAgentTool)+ MCP 桥工具 → 会话创建时
|
|
@@ -1391,7 +1393,7 @@ service.pluginCommandsProvider = () => pluginMgr.listCommands();
|
|
|
1391
1393
|
pluginMgr.onBgTasksChanged = () => service.refreshBackgroundServers();
|
|
1392
1394
|
service.pluginBgTasksProvider = () => pluginMgr.bgTasks();
|
|
1393
1395
|
service.pluginStopBgTask = (taskId) => pluginMgr.stopPluginBgTask(taskId);
|
|
1394
|
-
// 定时任务 Agent 工具的数据源(
|
|
1396
|
+
// 定时任务 Agent 工具的数据源(schedule 单 action:create/list/cancel):标准 pi 引擎的
|
|
1395
1397
|
// AgentService 才有 schedulerStore 字段,DSH service 没有 —— 有才设。
|
|
1396
1398
|
if ("schedulerStore" in service) {
|
|
1397
1399
|
service.schedulerStore = scheduler;
|
|
@@ -1631,13 +1633,15 @@ wss.on("connection", (ws) => {
|
|
|
1631
1633
|
if ((msg.type === "snapshot" || msg.type === "snapshot_delta") &&
|
|
1632
1634
|
lastSnapshotBytes > 0 &&
|
|
1633
1635
|
ws.bufferedAmount > Math.max(SNAPSHOT_BACKPRESSURE_MIN_BYTES, SNAPSHOT_BACKPRESSURE_FACTOR * lastSnapshotBytes)) {
|
|
1636
|
+
const wasFull = msg.type === "snapshot";
|
|
1634
1637
|
// 真正的慢客户端:丢弃是安全的,但不能「丢完就没了」——安排一次延迟
|
|
1635
1638
|
// 重发,等缓冲排空后快照最终必达(否则若此后再无事件,客户端将永久
|
|
1636
|
-
// 停留在旧快照)。重发仍走 flushSnapshot
|
|
1639
|
+
// 停留在旧快照)。重发仍走 flushSnapshot:缓冲未排空则再次顺延;
|
|
1640
|
+
// 若被丢弃的是全量快照(snapshot),重发必须强制 forceFull 保证客户端能拿到完整基线。
|
|
1637
1641
|
if (!snapshotRetryTimer) {
|
|
1638
1642
|
snapshotRetryTimer = setTimeout(() => {
|
|
1639
1643
|
snapshotRetryTimer = null;
|
|
1640
|
-
service.get(clientId ?? "")?.flushSnapshot();
|
|
1644
|
+
service.get(clientId ?? "")?.flushSnapshot(wasFull);
|
|
1641
1645
|
}, SNAPSHOT_RETRY_MS);
|
|
1642
1646
|
}
|
|
1643
1647
|
return;
|
|
@@ -1728,6 +1732,12 @@ wss.on("connection", (ws) => {
|
|
|
1728
1732
|
case "list_bg_servers":
|
|
1729
1733
|
void cs.listBgServers();
|
|
1730
1734
|
break;
|
|
1735
|
+
case "set_bg_keep":
|
|
1736
|
+
cs.setBackgroundKeep(msg.port, msg.keep);
|
|
1737
|
+
break;
|
|
1738
|
+
case "clean_bg_leftovers":
|
|
1739
|
+
void cs.cleanBackgroundLeftovers(msg.minutes);
|
|
1740
|
+
break;
|
|
1731
1741
|
case "new_chat":
|
|
1732
1742
|
void cs.newChat(msg.preset, msg.ephemeral);
|
|
1733
1743
|
break;
|
|
@@ -1759,6 +1769,15 @@ wss.on("connection", (ws) => {
|
|
|
1759
1769
|
send({ type: "tool_info", name: msg.name, found: false, unsupported: true });
|
|
1760
1770
|
}
|
|
1761
1771
|
break;
|
|
1772
|
+
case "get_tool_prompt":
|
|
1773
|
+
// 设置页逐工具文案编辑器:取「出厂默认 + 当前覆盖」。
|
|
1774
|
+
if (typeof cs.getToolPrompt === "function") {
|
|
1775
|
+
void cs.getToolPrompt(msg.name);
|
|
1776
|
+
}
|
|
1777
|
+
else {
|
|
1778
|
+
send({ type: "tool_prompt", name: msg.name, found: false, unsupported: true });
|
|
1779
|
+
}
|
|
1780
|
+
break;
|
|
1762
1781
|
case "get_compacted_messages":
|
|
1763
1782
|
void cs.getCompactedMessages?.(msg.compactionMessageId, msg.conversationId);
|
|
1764
1783
|
break;
|
|
@@ -2122,6 +2141,7 @@ wss.on("connection", (ws) => {
|
|
|
2122
2141
|
customSystemPrompt: msg.customSystemPrompt,
|
|
2123
2142
|
promptTemplate: msg.promptTemplate,
|
|
2124
2143
|
promptOverrides: msg.promptOverrides,
|
|
2144
|
+
toolPromptOverrides: msg.toolPromptOverrides,
|
|
2125
2145
|
disabledSkills: msg.disabledSkills,
|
|
2126
2146
|
disabledExtensions: msg.disabledExtensions,
|
|
2127
2147
|
disabledAgentTools: msg.disabledAgentTools,
|
|
@@ -2133,6 +2153,8 @@ wss.on("connection", (ws) => {
|
|
|
2133
2153
|
terminalBashMaxForegroundMs: msg.terminalBashMaxForegroundMs,
|
|
2134
2154
|
toolWatchdogTimeoutMs: msg.toolWatchdogTimeoutMs,
|
|
2135
2155
|
readDirEnabled: msg.readDirEnabled,
|
|
2156
|
+
bgAutoCleanupMin: msg.bgAutoCleanupMin,
|
|
2157
|
+
toolLazyLoading: msg.toolLazyLoading,
|
|
2136
2158
|
toolApprovalEnabled: msg.toolApprovalEnabled,
|
|
2137
2159
|
editSoftEnabled: msg.editSoftEnabled,
|
|
2138
2160
|
questionnaireEnabled: msg.questionnaireEnabled,
|
|
@@ -2555,6 +2577,22 @@ wss.on("connection", (ws) => {
|
|
|
2555
2577
|
case "save_preset":
|
|
2556
2578
|
void cs.savePreset(msg.name);
|
|
2557
2579
|
break;
|
|
2580
|
+
// -- 预设分享(server/preset-share.ts,docs/preset-sharing.md)------
|
|
2581
|
+
case "preset_export":
|
|
2582
|
+
void cs.exportPreset(msg);
|
|
2583
|
+
break;
|
|
2584
|
+
case "preset_import":
|
|
2585
|
+
void cs.importPreset(msg);
|
|
2586
|
+
break;
|
|
2587
|
+
case "preset_import_url":
|
|
2588
|
+
void cs.importPresetFromUrl(msg);
|
|
2589
|
+
break;
|
|
2590
|
+
case "preset_catalog":
|
|
2591
|
+
void cs.pushPresetCatalog(msg);
|
|
2592
|
+
break;
|
|
2593
|
+
case "preset_share":
|
|
2594
|
+
void cs.sharePreset(msg);
|
|
2595
|
+
break;
|
|
2558
2596
|
case "save_subagent_template":
|
|
2559
2597
|
void cs.saveSubagentTemplate(msg.template);
|
|
2560
2598
|
break;
|
|
@@ -2711,8 +2749,10 @@ wss.on("connection", (ws) => {
|
|
|
2711
2749
|
.attach(cid, send)
|
|
2712
2750
|
.then((cs) => {
|
|
2713
2751
|
clearTimeout(slowTimer);
|
|
2714
|
-
if (closed)
|
|
2752
|
+
if (closed) {
|
|
2753
|
+
service.detach(cid, send);
|
|
2715
2754
|
return;
|
|
2755
|
+
}
|
|
2716
2756
|
// Plugin catalog: re-scan + activate new dirs on every attach so
|
|
2717
2757
|
// freshly dropped plugins show up without a server restart.
|
|
2718
2758
|
pluginMgr
|
|
@@ -2740,7 +2780,9 @@ wss.on("connection", (ws) => {
|
|
|
2740
2780
|
// 插件清单【先于】快照推送:前端渲染历史消息前就拿到 renderer
|
|
2741
2781
|
// 注册表(plugin-fence.ts),`` ```lang `` 围栏才能立即命中插件;
|
|
2742
2782
|
// 否则消息先落成普通代码块,清单后到也不会重渲。
|
|
2743
|
-
|
|
2783
|
+
// 新连接/新客户端 attach 首次快照必须强制全量(forceFull=true),
|
|
2784
|
+
// 保证新标签页/刷新页能立刻拿到完整的会话基线,绝不因增量 delta 而卡在加载中。
|
|
2785
|
+
cs.flushSnapshot(true);
|
|
2744
2786
|
// 内置定时任务列表随附推一次(后续变更经 pushSchedulerTasks 广播)。
|
|
2745
2787
|
try {
|
|
2746
2788
|
send({ type: "scheduler_tasks", tasks: scheduler.list() });
|
|
@@ -2754,8 +2796,8 @@ wss.on("connection", (ws) => {
|
|
|
2754
2796
|
if (closed)
|
|
2755
2797
|
return;
|
|
2756
2798
|
// ensureLoaded 失败(如磁盘读错)不能卡死快照——前端 30s 无消息
|
|
2757
|
-
//
|
|
2758
|
-
cs.flushSnapshot();
|
|
2799
|
+
// 会重连,重连又失败会陷入循环。至少把状态推下去(同样强制全量)。
|
|
2800
|
+
cs.flushSnapshot(true);
|
|
2759
2801
|
replayQueued();
|
|
2760
2802
|
});
|
|
2761
2803
|
// hello may carry the UI locale — persist it before replaying
|
|
@@ -2775,6 +2817,10 @@ wss.on("connection", (ws) => {
|
|
|
2775
2817
|
};
|
|
2776
2818
|
})
|
|
2777
2819
|
.catch((err) => {
|
|
2820
|
+
clearTimeout(slowTimer);
|
|
2821
|
+
if (closed) {
|
|
2822
|
+
service.detach(cid, send);
|
|
2823
|
+
}
|
|
2778
2824
|
// Admission refused (quiesce): close the socket so the browser
|
|
2779
2825
|
// reconnect loop keeps retrying until admission reopens. Do NOT
|
|
2780
2826
|
// leave a half-alive connection that can only show an error.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// load-tools-tool.ts — 延迟加载模式下模型拉取工具 schema 的唯一入口。
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// 背景:模型每轮都会拿到**全部活跃工具**的名字 + 完整参数 schema,几十个工具加起来
|
|
5
|
+
// 是几万字符的常驻开销(设置页「查看工具 schema」能看到了多少)。延迟加载把工具分成
|
|
6
|
+
// 两层:
|
|
7
|
+
// - 常驻:核心工具(bash/read/edit/write)+ 本工具;
|
|
8
|
+
// - 目录:其余工具只在系统提示词里以「名字 + 一行摘要」出现(见 prompt-composer 的
|
|
9
|
+
// tool catalog 段)。
|
|
10
|
+
// 模型要用某个目录里的工具时先调本工具,那批工具才会被激活 —— SDK 的中途工具变更会
|
|
11
|
+
// 把新增工具以 defer_loading / tool_search 的形式注入(见 agent-session 的
|
|
12
|
+
// `_preparePromptAndToolLoadout`),不占首轮上下文。
|
|
13
|
+
//
|
|
14
|
+
// 与 skills 的 `skill` 工具同构:名录常驻、正文按需。区别只在「正文」是工具 schema。
|
|
15
|
+
//
|
|
16
|
+
// 文案约定:工具 definition(description/promptSnippet/promptGuidelines)纯英文;
|
|
17
|
+
// per-call 返回文本按 lang 走 pick(lang, zh, en, key)。
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
20
|
+
import { Type } from "typebox";
|
|
21
|
+
import { pick } from "./i18n.js";
|
|
22
|
+
import { LOAD_TOOLS_TOOL_NAME } from "./tool-manager.js";
|
|
23
|
+
/** 单次最多加载多少(防模型一口气把整个目录塞回来)。 */
|
|
24
|
+
export const LOAD_TOOLS_MAX = 20;
|
|
25
|
+
function describe(t) {
|
|
26
|
+
const text = (t.description ?? t.summary ?? "").trim().split("\n")[0] ?? "";
|
|
27
|
+
return text.length > 240 ? `${text.slice(0, 240)}…` : text;
|
|
28
|
+
}
|
|
29
|
+
export function makeLoadToolsTool(host, lang) {
|
|
30
|
+
const getLang = lang ?? (() => "en");
|
|
31
|
+
const text = (t, details = {}) => ({
|
|
32
|
+
content: [{ type: "text", text: t }],
|
|
33
|
+
details,
|
|
34
|
+
});
|
|
35
|
+
return defineTool({
|
|
36
|
+
name: LOAD_TOOLS_TOOL_NAME,
|
|
37
|
+
label: "Load tools",
|
|
38
|
+
description: "Attach the full parameter schema of tools listed in the system prompt's tool catalog. " +
|
|
39
|
+
"Tools whose schema is not loaded are shown there by name + one-line summary; load the ones you need " +
|
|
40
|
+
"BEFORE calling them. Loaded tools stay available for the rest of the conversation.",
|
|
41
|
+
promptSnippet: "load catalog tools you are about to use",
|
|
42
|
+
promptGuidelines: [
|
|
43
|
+
"When a task needs a tool that is only listed in the catalog (name + one-line summary, no schema yet), " +
|
|
44
|
+
"call load_tools with its name first instead of guessing arguments",
|
|
45
|
+
"Load every tool you expect to need in ONE call — each load re-declares the tool set",
|
|
46
|
+
],
|
|
47
|
+
parameters: Type.Object({
|
|
48
|
+
tools: Type.Array(Type.String(), {
|
|
49
|
+
description: `Tool names to load (1-${LOAD_TOOLS_MAX} per call), exactly as listed in the catalog.`,
|
|
50
|
+
minItems: 1,
|
|
51
|
+
maxItems: LOAD_TOOLS_MAX,
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
execute: async (_id, params) => {
|
|
55
|
+
const l = getLang();
|
|
56
|
+
const asked = params.tools;
|
|
57
|
+
const names = Array.isArray(asked)
|
|
58
|
+
? [
|
|
59
|
+
...new Set(asked
|
|
60
|
+
.filter((n) => typeof n === "string")
|
|
61
|
+
.map((n) => n.trim())
|
|
62
|
+
.filter(Boolean)),
|
|
63
|
+
]
|
|
64
|
+
: [];
|
|
65
|
+
if (names.length === 0) {
|
|
66
|
+
return text(pick(l, "没有给出要加载的工具名。", "No tool names given.", "loadtools.names.empty"), {
|
|
67
|
+
loaded: [],
|
|
68
|
+
rejected: [],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const { loaded, rejected } = host.load(names.slice(0, LOAD_TOOLS_MAX));
|
|
72
|
+
const lines = [];
|
|
73
|
+
if (loaded.length > 0) {
|
|
74
|
+
lines.push(pick(l, `已加载 ${loaded.length} 个工具(完整参数 schema 已附上,本对话后续轮次都可用):`, `Loaded ${loaded.length} tool(s) — their full parameter schema is now attached for the rest of this conversation:`, "loadtools.loaded", { count: loaded.length }));
|
|
75
|
+
for (const t of loaded) {
|
|
76
|
+
const d = describe(t);
|
|
77
|
+
lines.push(`- ${t.name}${d ? `: ${d}` : ""}`);
|
|
78
|
+
// guidelines 不进系统提示词(会随加载变化、打坏前缀缓存),在此随回执交付。
|
|
79
|
+
for (const g of t.guidelines ?? []) {
|
|
80
|
+
const rule = g.trim();
|
|
81
|
+
if (rule)
|
|
82
|
+
lines.push(` - ${rule}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const r of rejected) {
|
|
87
|
+
lines.push(pick(l, `- ${r.name}: ${r.reason}`, `- ${r.name}: ${r.reason}`, "loadtools.rejected", {
|
|
88
|
+
name: r.name,
|
|
89
|
+
reason: r.reason,
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
if (loaded.length === 0 && rejected.length === 0) {
|
|
93
|
+
const catalog = host.listLoadable();
|
|
94
|
+
lines.push(pick(l, "没有可加载的工具了。当前可加载:", "No tools left to load. Available:", "loadtools.none"));
|
|
95
|
+
lines.push(...catalog.map((t) => `- ${t.name}`));
|
|
96
|
+
}
|
|
97
|
+
return text(lines.join("\n"), { loaded: loaded.map((t) => t.name), rejected });
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
package/dist/server/lsp-tool.js
CHANGED
|
@@ -856,18 +856,12 @@ export function makeLspTool(options) {
|
|
|
856
856
|
const getLang = options.lang ?? (() => "en");
|
|
857
857
|
return defineTool({
|
|
858
858
|
name: LSP_TOOL_NAME,
|
|
859
|
-
promptSnippet: "
|
|
859
|
+
promptSnippet: "semantic code intelligence (definitions, references, diagnostics, impact)",
|
|
860
860
|
label: "LSP code intelligence",
|
|
861
|
-
description:
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
- \`diagnostics\`: compiler/type errors and warnings for \`path\` (whole file).
|
|
866
|
-
- \`documentSymbol\`: hierarchical symbol outline with line spans for \`path\`.
|
|
867
|
-
- \`read_symbol\`: read the body of \`symbol\` in \`path\` (e.g. "parseConfig").
|
|
868
|
-
- \`workspaceSymbol\`: search symbols across the workspace by \`query\`.
|
|
869
|
-
- \`cascade\`: impact check for \`path\` — report diagnostics of files referencing it.
|
|
870
|
-
Lines are 1-indexed.`,
|
|
861
|
+
description: "IDE-grade semantic analysis (LSP) across the workspace (lines are 1-indexed). `definition` / `references` / `hover`: " +
|
|
862
|
+
"resolve the symbol at `line`/`character` in `path` to its definition, workspace usages, or type and docs. `diagnostics`: " +
|
|
863
|
+
"file errors/warnings. `documentSymbol`: symbol outline. `read_symbol`: body of `symbol` in `path`. `workspaceSymbol`: " +
|
|
864
|
+
"symbols matching `query`. `cascade`: diagnostics of files referencing `path`.",
|
|
871
865
|
parameters: Type.Object({
|
|
872
866
|
action: Type.Unsafe({
|
|
873
867
|
type: "string",
|
|
@@ -884,16 +878,16 @@ Lines are 1-indexed.`,
|
|
|
884
878
|
description: "The LSP operation to perform.",
|
|
885
879
|
}),
|
|
886
880
|
path: Type.Optional(Type.String({
|
|
887
|
-
description: "Workspace-relative or absolute path
|
|
881
|
+
description: "Workspace-relative or absolute file path (required for every action except workspaceSymbol).",
|
|
888
882
|
})),
|
|
889
883
|
symbol: Type.Optional(Type.String({
|
|
890
|
-
description: "Symbol
|
|
884
|
+
description: "Symbol for 'read_symbol' (e.g. 'fn' or 'Class.method').",
|
|
891
885
|
})),
|
|
892
886
|
query: Type.Optional(Type.String({
|
|
893
|
-
description: "Search query for 'workspaceSymbol'
|
|
887
|
+
description: "Search query for 'workspaceSymbol'.",
|
|
894
888
|
})),
|
|
895
889
|
line: Type.Optional(Type.Number({
|
|
896
|
-
description: "1-indexed line
|
|
890
|
+
description: "1-indexed line in the file.",
|
|
897
891
|
})),
|
|
898
892
|
character: Type.Optional(Type.Number({
|
|
899
893
|
description: "1-indexed column/character position (defaults to 1).",
|
|
@@ -901,7 +895,7 @@ Lines are 1-indexed.`,
|
|
|
901
895
|
timeout: Type.Optional(Type.Number({
|
|
902
896
|
minimum: 1,
|
|
903
897
|
maximum: 120,
|
|
904
|
-
description: "Timeout in seconds (
|
|
898
|
+
description: "Timeout in seconds (default 15).",
|
|
905
899
|
})),
|
|
906
900
|
allowInstall: Type.Optional(Type.Boolean({
|
|
907
901
|
description: "Install the missing language server into ~/.pi-web/lsp-servers (user-space, no sudo). Default false: the tool returns an installHint instead.",
|
|
@@ -5,8 +5,9 @@ import { pick } from "./i18n.js";
|
|
|
5
5
|
import { ensureMarkersRegistered, parseMarkers, getMarker, allMarkers, collectGuidance, listMarkerNames, } from "./markers/index.js";
|
|
6
6
|
import { loadStateFromBranch, appendSnapshot } from "./markers/store.js";
|
|
7
7
|
import { TODO_NAMESPACE, initTodoState } from "./markers/builtins/todo.js";
|
|
8
|
+
import { ACTION_NAMESPACE, initActionState } from "./markers/builtins/action.js";
|
|
8
9
|
ensureMarkersRegistered();
|
|
9
|
-
const
|
|
10
|
+
const _DEFAULT_MARKERS = {
|
|
10
11
|
markersEnabled: true,
|
|
11
12
|
disabledMarkers: [],
|
|
12
13
|
};
|
|
@@ -31,6 +32,8 @@ export class MarkerService {
|
|
|
31
32
|
isMarkerEnabled(name) {
|
|
32
33
|
if (!this.settings.markersEnabled)
|
|
33
34
|
return false;
|
|
35
|
+
if (name === "suggest" && this.settings.disabledMarkers.includes("action"))
|
|
36
|
+
return false;
|
|
34
37
|
return !this.settings.disabledMarkers.includes(name);
|
|
35
38
|
}
|
|
36
39
|
/** 当前服务端语言(英文默认,未接线前保持原有英文行为)。 */
|
|
@@ -63,10 +66,16 @@ export class MarkerService {
|
|
|
63
66
|
}
|
|
64
67
|
toggleMarker(name, enabled) {
|
|
65
68
|
const set = new Set(this.settings.disabledMarkers);
|
|
66
|
-
if (enabled)
|
|
69
|
+
if (enabled) {
|
|
67
70
|
set.delete(name);
|
|
68
|
-
|
|
71
|
+
if (name === "action")
|
|
72
|
+
set.delete("suggest");
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
69
75
|
set.add(name);
|
|
76
|
+
if (name === "action")
|
|
77
|
+
set.add("suggest");
|
|
78
|
+
}
|
|
70
79
|
this.settings.disabledMarkers = [...set];
|
|
71
80
|
this.host.stateStore.saveMarkerSettings(this.host.clientId, this.settings);
|
|
72
81
|
}
|
|
@@ -147,16 +156,19 @@ export class MarkerService {
|
|
|
147
156
|
const disabled = new Set(this.settings.disabledMarkers);
|
|
148
157
|
const states = new Map();
|
|
149
158
|
const getOrInit = (ns) => {
|
|
150
|
-
|
|
159
|
+
const canonicalNs = ns === "suggest" ? ACTION_NAMESPACE : ns;
|
|
160
|
+
let st = states.get(canonicalNs);
|
|
151
161
|
if (st !== undefined)
|
|
152
162
|
return st;
|
|
153
|
-
if (
|
|
154
|
-
st = this.getState(conversationId,
|
|
163
|
+
if (canonicalNs === TODO_NAMESPACE)
|
|
164
|
+
st = this.getState(conversationId, canonicalNs, initTodoState);
|
|
165
|
+
else if (canonicalNs === ACTION_NAMESPACE)
|
|
166
|
+
st = this.getState(conversationId, canonicalNs, initActionState);
|
|
155
167
|
else {
|
|
156
|
-
const marker = getMarker(
|
|
168
|
+
const marker = getMarker(canonicalNs);
|
|
157
169
|
st = marker?.init ? marker.init() : {};
|
|
158
170
|
}
|
|
159
|
-
states.set(
|
|
171
|
+
states.set(canonicalNs, st);
|
|
160
172
|
return st;
|
|
161
173
|
};
|
|
162
174
|
const dirty = new Set();
|
|
@@ -188,9 +200,10 @@ export class MarkerService {
|
|
|
188
200
|
};
|
|
189
201
|
}
|
|
190
202
|
if (result.applied) {
|
|
191
|
-
// todo 落库;notify/conv 即时生效(通知已发 / 对话已重命名),无需快照。
|
|
192
|
-
|
|
193
|
-
|
|
203
|
+
// todo 与 action 落库;notify/conv 即时生效(通知已发 / 对话已重命名),无需快照。
|
|
204
|
+
const canonicalTool = token.tool === "suggest" ? ACTION_NAMESPACE : token.tool;
|
|
205
|
+
if (canonicalTool !== "notify" && canonicalTool !== "conv") {
|
|
206
|
+
dirty.add(canonicalTool);
|
|
194
207
|
}
|
|
195
208
|
}
|
|
196
209
|
else if (result.error) {
|
|
@@ -208,6 +221,9 @@ export class MarkerService {
|
|
|
208
221
|
this.saveState(conversationId, ns, mutated);
|
|
209
222
|
}
|
|
210
223
|
this.pushOverlay(conversationId);
|
|
224
|
+
if (dirty.has(ACTION_NAMESPACE)) {
|
|
225
|
+
this.host.onActionsChange?.(conversationId);
|
|
226
|
+
}
|
|
211
227
|
}
|
|
212
228
|
pushOverlay(conversationId) {
|
|
213
229
|
const lines = this.overlayLines(conversationId);
|
|
@@ -224,6 +240,8 @@ export class MarkerService {
|
|
|
224
240
|
overlayLines(conversationId) {
|
|
225
241
|
const lines = [];
|
|
226
242
|
for (const m of allMarkers()) {
|
|
243
|
+
if (m.name === "suggest")
|
|
244
|
+
continue;
|
|
227
245
|
if (this.settings.disabledMarkers.includes(m.name))
|
|
228
246
|
continue;
|
|
229
247
|
if (!m.overlay)
|
|
@@ -231,6 +249,8 @@ export class MarkerService {
|
|
|
231
249
|
let state;
|
|
232
250
|
if (m.name === TODO_NAMESPACE)
|
|
233
251
|
state = this.getState(conversationId, m.name, initTodoState);
|
|
252
|
+
else if (m.name === ACTION_NAMESPACE)
|
|
253
|
+
state = this.getState(conversationId, m.name, initActionState);
|
|
234
254
|
else {
|
|
235
255
|
state = this.getState(conversationId, m.name, () => m.init?.() ?? {});
|
|
236
256
|
if (state === undefined)
|
|
@@ -259,15 +279,36 @@ export class MarkerService {
|
|
|
259
279
|
getRawState(conversationId, namespace) {
|
|
260
280
|
if (namespace === TODO_NAMESPACE)
|
|
261
281
|
return this.getState(conversationId, namespace, initTodoState);
|
|
282
|
+
if (namespace === ACTION_NAMESPACE || namespace === "suggest")
|
|
283
|
+
return this.getState(conversationId, ACTION_NAMESPACE, initActionState);
|
|
262
284
|
const m = getMarker(namespace);
|
|
263
285
|
return this.getState(conversationId, namespace, () => m?.init?.() ?? {});
|
|
264
286
|
}
|
|
287
|
+
getActionSuggestions(conversationId) {
|
|
288
|
+
if (!this.isMarkerEnabled("action"))
|
|
289
|
+
return null;
|
|
290
|
+
const st = this.getState(conversationId, ACTION_NAMESPACE, initActionState);
|
|
291
|
+
if (!st || !st.actions || st.actions.length === 0)
|
|
292
|
+
return null;
|
|
293
|
+
return st.actions.map((a) => ({ id: a.id, label: a.label, prompt: a.prompt }));
|
|
294
|
+
}
|
|
295
|
+
clearActions(conversationId) {
|
|
296
|
+
const st = this.getState(conversationId, ACTION_NAMESPACE, initActionState);
|
|
297
|
+
if (st && st.actions && st.actions.length > 0) {
|
|
298
|
+
st.actions = [];
|
|
299
|
+
this.saveState(conversationId, ACTION_NAMESPACE, st);
|
|
300
|
+
this.pushOverlay(conversationId);
|
|
301
|
+
this.host.onActionsChange?.(conversationId);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
265
304
|
/** 供设置面板展示的 marker 目录(含启用状态)。 */
|
|
266
|
-
/** UI 过滤:rename/title 是 conv 的别名,不单独展示。 */
|
|
305
|
+
/** UI 过滤:rename/title 是 conv 的别名,suggest 是 action 的别名,不单独展示。 */
|
|
267
306
|
listForUi() {
|
|
268
307
|
const seen = new Set();
|
|
269
308
|
const out = [];
|
|
270
309
|
for (const m of allMarkers()) {
|
|
310
|
+
if (m.name === "suggest")
|
|
311
|
+
continue;
|
|
271
312
|
if (seen.has(m.name))
|
|
272
313
|
continue;
|
|
273
314
|
seen.add(m.name);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* builtins/action.ts — 建议操作标记(期待用户操作)。
|
|
3
|
+
*
|
|
4
|
+
* 语法:
|
|
5
|
+
* [[action:suggest:<按钮文字>]] 添加快捷操作建议(点击发送该文字)
|
|
6
|
+
* [[action:suggest:<按钮显示>,prompt=<实际发送文本>]] 区分展示标签与实际发送内容
|
|
7
|
+
* [[action:suggest:label=<按钮显示>,prompt=<发送文本>]] kwargs 风格
|
|
8
|
+
* [[action:clear:all]] 清空当前建议操作
|
|
9
|
+
*
|
|
10
|
+
* 兼容操作别名:
|
|
11
|
+
* tool 兼容 action 与 suggest
|
|
12
|
+
* op 兼容 suggest / add / next / reply / choice / option / clear
|
|
13
|
+
*/
|
|
14
|
+
import { getServerBlock, pick } from "../../i18n.js";
|
|
15
|
+
export const ACTION_NAMESPACE = "action";
|
|
16
|
+
export function initActionState() {
|
|
17
|
+
return { actions: [], nextId: 1 };
|
|
18
|
+
}
|
|
19
|
+
const ACTION_GUIDANCE_ZH = [
|
|
20
|
+
"- 建议后续操作:[[action:suggest:<文字>]](当期待用户操作时,如是否继续、后续步骤选择;在对话最底部生成按钮,用户点击即发送该文字)",
|
|
21
|
+
"- 可指定不同按钮显示与发送内容:[[action:suggest:<按钮显示>,prompt=<实际发送文本>]]",
|
|
22
|
+
"- 清空候选操作:[[action:clear:all]]",
|
|
23
|
+
];
|
|
24
|
+
const ACTION_GUIDANCE_EN = [
|
|
25
|
+
"- Suggest next actions: [[action:suggest:<text>]] (when expecting user input, e.g. whether to continue, what to do next; creates buttons at the bottom of the conversation, clicked to send text immediately)",
|
|
26
|
+
"- Optional separate prompt: [[action:suggest:<label>,prompt=<text to send>]]",
|
|
27
|
+
"- Clear suggestions: [[action:clear:all]]",
|
|
28
|
+
];
|
|
29
|
+
/** 语言感知的 action guidance:en 用英译、zh 用中文,默认英文。 */
|
|
30
|
+
export function getActionGuidance(lang = "en") {
|
|
31
|
+
return getServerBlock(lang, "markers.action.guidance", ACTION_GUIDANCE_ZH, ACTION_GUIDANCE_EN);
|
|
32
|
+
}
|
|
33
|
+
const VALID_ACTION_OPS = new Set(["suggest", "add", "next", "reply", "choice", "option", "action"]);
|
|
34
|
+
export const actionMarker = {
|
|
35
|
+
name: "action",
|
|
36
|
+
guidance: ACTION_GUIDANCE_ZH,
|
|
37
|
+
getGuidance: getActionGuidance,
|
|
38
|
+
async apply(token, _ctx, state, lang = "en") {
|
|
39
|
+
const op = token.op.toLowerCase();
|
|
40
|
+
if (op === "clear") {
|
|
41
|
+
state.actions = [];
|
|
42
|
+
return {
|
|
43
|
+
applied: true,
|
|
44
|
+
feedback: pick(lang, "已清空建议操作", "Cleared suggested actions", "markers.action.cleared"),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (!VALID_ACTION_OPS.has(op)) {
|
|
48
|
+
return {
|
|
49
|
+
applied: false,
|
|
50
|
+
error: pick(lang, `action 未知操作: ${token.op}(支持 suggest/next/add/clear)`, `action unknown operation: ${token.op} (supports suggest/next/add/clear)`, "markers.action.unknown.operation", { "token.op": token.op }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// 提取 label 与 prompt:
|
|
54
|
+
// args: token.args.join(",").trim() (兼容含逗号的正文,如 "是,继续执行")
|
|
55
|
+
const argsText = token.args.join(",").trim();
|
|
56
|
+
const kwLabel = token.kwargs["label"]?.trim() || "";
|
|
57
|
+
const kwPrompt = token.kwargs["prompt"]?.trim() || "";
|
|
58
|
+
const kwText = token.kwargs["text"]?.trim() || "";
|
|
59
|
+
let prompt = kwPrompt || argsText || kwText || kwLabel;
|
|
60
|
+
let label = kwLabel || argsText || kwText || prompt;
|
|
61
|
+
if (!label && !prompt) {
|
|
62
|
+
return {
|
|
63
|
+
applied: false,
|
|
64
|
+
error: pick(lang, "action:suggest 需要操作描述 [[action:suggest:<文字>]]", "action:suggest requires an action description [[action:suggest:<text>]]", "markers.action.requires.text"),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!prompt)
|
|
68
|
+
prompt = label;
|
|
69
|
+
if (!label)
|
|
70
|
+
label = prompt;
|
|
71
|
+
// 字符长度封顶保护
|
|
72
|
+
if (label.length > 80)
|
|
73
|
+
label = label.slice(0, 80);
|
|
74
|
+
if (prompt.length > 2000)
|
|
75
|
+
prompt = prompt.slice(0, 2000);
|
|
76
|
+
// 去重
|
|
77
|
+
const existing = state.actions.find((a) => a.label === label && a.prompt === prompt);
|
|
78
|
+
if (existing) {
|
|
79
|
+
return {
|
|
80
|
+
applied: true,
|
|
81
|
+
feedback: pick(lang, `建议操作已存在: ${label}`, `Suggested action already exists: ${label}`, "markers.action.already.exists", { label }),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// 数量上限 8 个,超限剔除最早的一项
|
|
85
|
+
if (state.actions.length >= 8) {
|
|
86
|
+
state.actions.shift();
|
|
87
|
+
}
|
|
88
|
+
const id = `act-${state.nextId++}`;
|
|
89
|
+
state.actions.push({ id, label, prompt });
|
|
90
|
+
return {
|
|
91
|
+
applied: true,
|
|
92
|
+
feedback: pick(lang, `已添加建议操作: ${label}`, `Added suggested action: ${label}`, "markers.action.added", {
|
|
93
|
+
label,
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
overlay(state) {
|
|
98
|
+
if (!state || state.actions.length === 0)
|
|
99
|
+
return undefined;
|
|
100
|
+
const lines = state.actions.map((a) => (a.label === a.prompt ? ` [${a.label}]` : ` [${a.label}] -> ${a.prompt}`));
|
|
101
|
+
return { tool: "action", lines: [`${state.actions.length} action(s)`, ...lines] };
|
|
102
|
+
},
|
|
103
|
+
init: initActionState,
|
|
104
|
+
};
|
|
105
|
+
export const suggestMarker = {
|
|
106
|
+
...actionMarker,
|
|
107
|
+
name: "suggest",
|
|
108
|
+
};
|
|
@@ -5,6 +5,7 @@ import { registerMarker } from "./registry.js";
|
|
|
5
5
|
import { todoMarker } from "./builtins/todo.js";
|
|
6
6
|
import { notifyMarker } from "./builtins/notify.js";
|
|
7
7
|
import { renameMarker } from "./builtins/rename.js";
|
|
8
|
+
import { actionMarker, suggestMarker } from "./builtins/action.js";
|
|
8
9
|
let initialized = false;
|
|
9
10
|
export function ensureMarkersRegistered() {
|
|
10
11
|
if (initialized)
|
|
@@ -12,9 +13,11 @@ export function ensureMarkersRegistered() {
|
|
|
12
13
|
registerMarker(todoMarker);
|
|
13
14
|
registerMarker(notifyMarker);
|
|
14
15
|
registerMarker(renameMarker);
|
|
16
|
+
registerMarker(actionMarker);
|
|
17
|
+
registerMarker(suggestMarker);
|
|
15
18
|
initialized = true;
|
|
16
19
|
}
|
|
17
|
-
export { todoMarker, notifyMarker, renameMarker };
|
|
20
|
+
export { todoMarker, notifyMarker, renameMarker, actionMarker, suggestMarker };
|
|
18
21
|
export * from "./marker.js";
|
|
19
22
|
export * from "./registry.js";
|
|
20
23
|
export * from "./store.js";
|
|
@@ -156,6 +156,8 @@ async function fetchJson(fetchFn, url, maxBytes, timeoutMs, signal) {
|
|
|
156
156
|
signal.removeEventListener("abort", onAbort);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
// 手写 TTL 缓存而非通用 memoize:双键(openrouter/modelsdev)共享一个 Map,
|
|
160
|
+
// 且 compute 是 async fetch——单值同步的 memoizeWithTtl 覆盖不了(issue #470 处置说明)。
|
|
159
161
|
/** 目录抓取缓存(24h TTL,进程内;首跑后无感)。 */
|
|
160
162
|
const catalogCache = new Map();
|
|
161
163
|
const CATALOG_TTL_MS = 24 * 3600 * 1000;
|
|
@@ -24,10 +24,23 @@
|
|
|
24
24
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
25
25
|
import { fileURLToPath } from "node:url";
|
|
26
26
|
import { dirname, join } from "node:path";
|
|
27
|
-
/**
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
/** Supported patch pairs across SDK versions (0.87.x, 1.1.0+). */
|
|
28
|
+
const PATCH_PAIRS = [
|
|
29
|
+
// SDK 0.87.x
|
|
30
|
+
{
|
|
31
|
+
old: "getModels: () => mergeModels(provider.getModels(), dynamicModels),",
|
|
32
|
+
new: "getModels: () => (dynamicModels.length > 0 ? dynamicModels : provider.getModels()),",
|
|
33
|
+
},
|
|
34
|
+
// SDK 1.1.0+ (typed model shards: chat, image, classifier)
|
|
35
|
+
{
|
|
36
|
+
old: 'getModels: () => mergeModels(provider.getModels(), dynamicModels.filter((model) => isModelType(model, "chat"))),',
|
|
37
|
+
new: 'getModels: () => (dynamicModels.length > 0 ? dynamicModels.filter((model) => isModelType(model, "chat")) : provider.getModels()),',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
old: "getAllModels: () => mergeModels(provider.getAllModels?.() ?? provider.getModels(), dynamicModels),",
|
|
41
|
+
new: "getAllModels: () => (dynamicModels.length > 0 ? dynamicModels : (provider.getAllModels?.() ?? provider.getModels())),",
|
|
42
|
+
},
|
|
43
|
+
];
|
|
31
44
|
/** Absolute path of the installed remote-catalog-provider.js, or null. */
|
|
32
45
|
function remoteCatalogFile() {
|
|
33
46
|
try {
|
|
@@ -45,12 +58,17 @@ function applyPatch() {
|
|
|
45
58
|
const file = remoteCatalogFile();
|
|
46
59
|
if (!file || !existsSync(file))
|
|
47
60
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
let src = readFileSync(file, "utf8");
|
|
62
|
+
let changed = false;
|
|
63
|
+
for (const { old: oldPattern, new: newPattern } of PATCH_PAIRS) {
|
|
64
|
+
if (src.includes(oldPattern) && !src.includes(newPattern)) {
|
|
65
|
+
src = src.replace(oldPattern, newPattern);
|
|
66
|
+
changed = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (changed) {
|
|
70
|
+
writeFileSync(file, src, "utf8");
|
|
71
|
+
}
|
|
54
72
|
}
|
|
55
73
|
catch {
|
|
56
74
|
// best-effort — without the patch the SDK keeps its default union merge
|