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.
- package/CHANGELOG.md +90 -1
- package/README.md +48 -45
- package/README.zh-CN.md +43 -40
- package/bin/pi-web-ui.mjs +172 -40
- package/dist/server/agent-formatters.js +191 -0
- package/dist/server/agent-service-daemon.js +1266 -0
- package/dist/server/agent-service.js +9851 -11892
- package/dist/server/approval-default-rules.js +158 -0
- package/dist/server/approval-rules.js +130 -184
- package/dist/server/ask-user-question-tool.js +94 -0
- package/dist/server/attachment-store.js +38 -1
- package/dist/server/attachments.js +55 -0
- package/dist/server/bash-tool.js +83 -0
- package/dist/server/bg-servers.js +82 -2
- package/dist/server/browser-page-tool.js +207 -0
- package/dist/server/claim-files-tool.js +4 -4
- package/dist/server/client-id-utils.js +51 -0
- package/dist/server/client-state.js +63 -1
- package/dist/server/compact-context-tool.js +10 -9
- package/dist/server/compaction-markers.js +34 -1
- package/dist/server/context-budget-runner.js +43 -0
- package/dist/server/conversation-read-tool.js +7 -8
- package/dist/server/conversation-touches.js +19 -0
- package/dist/server/dangling-tools.js +18 -5
- package/dist/server/delegate-mode.js +1 -0
- package/dist/server/delegate-task.js +10 -14
- 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 +125 -13
- package/dist/server/edit-soft-tool.js +10 -12
- package/dist/server/eval-tool.js +4 -5
- package/dist/server/goal-evidence.js +180 -0
- package/dist/server/goal-service.js +49 -9
- package/dist/server/hashline-engine.js +199 -32
- package/dist/server/index.js +212 -944
- package/dist/server/left-panel-running.js +115 -0
- package/dist/server/load-tools-tool.js +100 -0
- package/dist/server/lsp-tool.js +50 -28
- 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/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/patch-remote-catalog.js +28 -10
- package/dist/server/patch-tool.js +9 -8
- package/dist/server/persona-chain.js +63 -0
- package/dist/server/plan-mode.js +9 -6
- package/dist/server/plan-update-tool.js +96 -0
- package/dist/server/plugin-api-catalog.js +30 -3
- package/dist/server/plugin-conversation-view.js +47 -0
- package/dist/server/plugin-facilities.js +13 -3
- package/dist/server/plugin-ui-slots.js +39 -0
- package/dist/server/plugins.js +183 -63
- package/dist/server/present-files-tool.js +10 -11
- package/dist/server/preset-fields.js +700 -0
- package/dist/server/preset-share.js +1179 -0
- package/dist/server/process-utils.js +30 -0
- package/dist/server/prompt-assembler.js +80 -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/scm-commitmsg.js +74 -0
- package/dist/server/sdk-origin.js +125 -37
- 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 +115 -84
- package/dist/server/skill-content-filler.js +33 -0
- package/dist/server/skill-tool.js +3 -4
- package/dist/server/subagent-handoff.js +18 -0
- package/dist/server/subagent-helpers.js +88 -0
- package/dist/server/subagents.js +15 -22
- package/dist/server/terminals.js +171 -91
- package/dist/server/tool-approval.js +3 -1
- package/dist/server/tool-guards.js +527 -0
- package/dist/server/tool-host-factories.js +217 -0
- package/dist/server/tool-manager.js +84 -23
- 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/wait-subscription-scan.js +46 -1
- package/dist/server/workspace-snapshot.js +60 -11
- package/extensions/webui.ts +90 -24
- package/package.json +5 -3
- package/plugin-sdk/README.md +25 -4
- package/plugin-sdk/import-check.mjs +210 -0
- package/plugin-sdk/index.d.ts +21 -1
- package/plugin-sdk/index.mjs +6 -0
- package/plugins/catalog.json +53 -2
- package/themes/aetheris.css +3 -1
- package/themes/translucent.css +8 -1
- package/themes/transparent.css +9 -1
- package/themes/zhupi-dark.css +1 -1
- package/themes/zhupi.css +1 -1
- package/web/dist/assets/{TerminalPanel-NerrJlTS.js → TerminalPanel-DD7I5_aC.js} +2 -2
- package/web/dist/assets/index-CpjA1YdT.css +1 -0
- package/web/dist/assets/index-nKn87VuM.js +678 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BdMaGCcs.css +0 -1
- package/web/dist/assets/index-ByCBN4Kt.js +0 -368
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dispatch-plugin-handlers — WebSocket 插件管理与生命周期事件分发路由处理器。
|
|
3
|
+
*
|
|
4
|
+
* 负责:
|
|
5
|
+
* - 插件双向通信(plugin_message)与配置持久化(plugin_settings)
|
|
6
|
+
* - 插件市场目录同步、添加与移除(plugin_catalog_*)
|
|
7
|
+
* - 插件后台作业(安装/更新/卸载/取消及安装前检查,plugin_job_*)
|
|
8
|
+
* - 插件 API 注册面只读目录(plugin_api_catalog)
|
|
9
|
+
* - 插件特权目录授权、网络/LLM能力授权及撤销(plugin_path_* / plugin_permission_*)
|
|
10
|
+
* - 特权 DOM 两步握手授权与应答(plugin_dom_consent_*)
|
|
11
|
+
*
|
|
12
|
+
* 从 server/index.ts 抽出为独立模块。
|
|
13
|
+
*/
|
|
14
|
+
import { randomUUID } from "node:crypto";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { WebSocket } from "ws";
|
|
17
|
+
import { buildPluginJobArgs, inspectInstallSpec } from "./plugin-installer.js";
|
|
18
|
+
import { syncPluginCatalog } from "./plugin-catalog-sync.js";
|
|
19
|
+
export function handlePluginMessage(msg, ctx) {
|
|
20
|
+
const { pluginMgr, pluginInstaller, cs, clientId, send, dataDir, cwd, clients, pendingPathRequests, pendingPermissionRequests, pendingDomConsents, findDomConsentById, applyDomConsent, pushPluginGrants, pushPluginPermissions, reloadPluginsAndPush, confirmPluginInstallHelper, } = ctx;
|
|
21
|
+
switch (msg.type) {
|
|
22
|
+
case "plugin_message":
|
|
23
|
+
pluginMgr.handleMessage(msg.pluginId, msg.payload, clientId ?? undefined);
|
|
24
|
+
return true;
|
|
25
|
+
case "plugin_settings": {
|
|
26
|
+
const r = pluginMgr.savePluginSettings(msg.pluginId, msg.values ?? {}, () => cs?.getLang() ?? "en");
|
|
27
|
+
if (r.error) {
|
|
28
|
+
cs?.emitNotice?.("error", `插件设置保存失败:${r.error}`, `Failed to save plugin settings: ${r.error}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
cs?.emitNotice?.("info", "插件设置已保存", "Plugin settings saved");
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
case "plugins_reload":
|
|
36
|
+
void pluginMgr.reload(() => cs?.getLang() ?? "en").then(() => pluginMgr.pushToAll());
|
|
37
|
+
return true;
|
|
38
|
+
case "plugin_catalog_add": {
|
|
39
|
+
const r = pluginMgr.addCatalogEntry(msg.entry ?? {}, () => cs?.getLang() ?? "en");
|
|
40
|
+
if (r.error) {
|
|
41
|
+
cs?.emitNotice?.("error", `添加到插件列表失败:${r.error}`, `Failed to add to plugin list: ${r.error}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
cs?.emitNotice?.("info", "已添加到插件列表", "Added to the plugin list");
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
case "plugin_catalog_remove": {
|
|
49
|
+
const r = pluginMgr.removeCatalogEntry(msg.id, () => cs?.getLang() ?? "en");
|
|
50
|
+
if (r.error) {
|
|
51
|
+
cs?.emitNotice?.("error", `从插件列表移除失败:${r.error}`, `Failed to remove from plugin list: ${r.error}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
cs?.emitNotice?.("info", "已从插件列表移除", "Removed from the plugin list");
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
case "plugin_job": {
|
|
59
|
+
const jobLang = () => cs?.getLang() ?? "en";
|
|
60
|
+
const jobId = String(msg.jobId ?? "");
|
|
61
|
+
const pluginId = String(msg.id ?? "");
|
|
62
|
+
const jobAction = msg.action;
|
|
63
|
+
const jobSpec = {
|
|
64
|
+
jobId,
|
|
65
|
+
action: jobAction,
|
|
66
|
+
id: pluginId,
|
|
67
|
+
source: msg.source,
|
|
68
|
+
build: msg.build === true,
|
|
69
|
+
noBuild: msg.noBuild === true,
|
|
70
|
+
};
|
|
71
|
+
const jobDone = (ok, error) => {
|
|
72
|
+
send({
|
|
73
|
+
type: "plugin_job",
|
|
74
|
+
jobId,
|
|
75
|
+
action: jobAction,
|
|
76
|
+
pluginId,
|
|
77
|
+
phase: "done",
|
|
78
|
+
ok,
|
|
79
|
+
...(error ? { error } : {}),
|
|
80
|
+
output: "",
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const argCheck = buildPluginJobArgs(jobSpec, dataDir, jobLang);
|
|
84
|
+
if ("error" in argCheck) {
|
|
85
|
+
jobDone(false, argCheck.error);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (jobAction === "install" || jobAction === "update") {
|
|
89
|
+
const alreadyGranted = pluginMgr.permGrants.has("plugin-installer", "net", { host: "github.com" });
|
|
90
|
+
if (!alreadyGranted) {
|
|
91
|
+
send({
|
|
92
|
+
type: "plugin_job",
|
|
93
|
+
jobId,
|
|
94
|
+
action: jobAction,
|
|
95
|
+
pluginId,
|
|
96
|
+
phase: "start",
|
|
97
|
+
});
|
|
98
|
+
send({
|
|
99
|
+
type: "plugin_job",
|
|
100
|
+
jobId,
|
|
101
|
+
action: jobAction,
|
|
102
|
+
pluginId,
|
|
103
|
+
phase: "log",
|
|
104
|
+
line: jobLang() === "zh" ? "等待确认安装授权…" : "Waiting for install confirmation…",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
void confirmPluginInstallHelper([{ id: pluginId, source: String(msg.source ?? "") }])
|
|
108
|
+
.then((confirmed) => {
|
|
109
|
+
if (!confirmed) {
|
|
110
|
+
jobDone(false, jobLang() === "zh"
|
|
111
|
+
? "用户未确认安装(拒绝或 120 秒超时)"
|
|
112
|
+
: "Installation not confirmed (rejected or timed out after 120s)");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
startPluginJob();
|
|
116
|
+
})
|
|
117
|
+
.catch(() => jobDone(false, jobLang() === "zh" ? "安装确认流程异常" : "Installation confirmation error"));
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
startPluginJob();
|
|
121
|
+
function startPluginJob() {
|
|
122
|
+
const started = pluginInstaller.start(jobSpec, {
|
|
123
|
+
lang: jobLang,
|
|
124
|
+
emit: (m) => send(m),
|
|
125
|
+
done: async (ok, info) => {
|
|
126
|
+
if (ok) {
|
|
127
|
+
await reloadPluginsAndPush(jobLang);
|
|
128
|
+
if (typeof cs?.checkPluginUpdates === "function") {
|
|
129
|
+
void cs.checkPluginUpdates(false);
|
|
130
|
+
}
|
|
131
|
+
const isZh = jobLang() === "zh";
|
|
132
|
+
const actionLabel = jobAction === "uninstall"
|
|
133
|
+
? isZh
|
|
134
|
+
? "卸载"
|
|
135
|
+
: "uninstalled"
|
|
136
|
+
: jobAction === "update"
|
|
137
|
+
? isZh
|
|
138
|
+
? "更新"
|
|
139
|
+
: "updated"
|
|
140
|
+
: isZh
|
|
141
|
+
? "安装"
|
|
142
|
+
: "installed";
|
|
143
|
+
cs?.emitNotice?.("info", `插件「${pluginId}」${actionLabel}完成`, `Plugin "${pluginId}" ${actionLabel} successfully`);
|
|
144
|
+
}
|
|
145
|
+
else if (info.error) {
|
|
146
|
+
cs?.emitNotice?.("error", `插件操作失败:${info.error}`, `Plugin operation failed: ${info.error}`);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
if (!started.ok)
|
|
151
|
+
jobDone(false, started.error);
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
case "plugin_job_cancel":
|
|
156
|
+
pluginInstaller.cancel(String(msg.jobId ?? ""));
|
|
157
|
+
return true;
|
|
158
|
+
case "plugin_api_catalog": {
|
|
159
|
+
const requestId = String(msg.requestId ?? "");
|
|
160
|
+
send({ type: "plugin_api_catalog_result", requestId, catalog: pluginMgr.getApiCatalog() });
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
case "plugin_install_inspect": {
|
|
164
|
+
const requestId = String(msg.requestId ?? "");
|
|
165
|
+
const source = String(msg.source ?? "");
|
|
166
|
+
void inspectInstallSpec(source, {
|
|
167
|
+
pluginsDir: pluginMgr.pluginsDir,
|
|
168
|
+
...(typeof msg.explicitId === "string" && msg.explicitId.trim() ? { explicitId: msg.explicitId.trim() } : {}),
|
|
169
|
+
force: msg.force === true,
|
|
170
|
+
}).then((r) => {
|
|
171
|
+
send({
|
|
172
|
+
type: "plugin_install_inspect_result",
|
|
173
|
+
requestId,
|
|
174
|
+
source,
|
|
175
|
+
kind: r.spec.kind,
|
|
176
|
+
suggestedId: r.suggestedId,
|
|
177
|
+
installed: r.installed,
|
|
178
|
+
...(r.problem ? { problem: r.problem } : {}),
|
|
179
|
+
...(r.detail ? { detail: r.detail } : {}),
|
|
180
|
+
...(r.manifest ? { manifest: r.manifest } : {}),
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
case "plugin_path_response": {
|
|
186
|
+
const id = String(msg.id ?? "");
|
|
187
|
+
const pending = pendingPathRequests.get(id);
|
|
188
|
+
if (pending && clientId && pending.recipients.has(clientId)) {
|
|
189
|
+
clearTimeout(pending.timer);
|
|
190
|
+
pendingPathRequests.delete(id);
|
|
191
|
+
pending.resolve(msg.ok === true);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
case "plugin_permission_response": {
|
|
196
|
+
const id = String(msg.id ?? "");
|
|
197
|
+
const pending = pendingPermissionRequests.get(id);
|
|
198
|
+
if (pending && clientId && pending.recipients.has(clientId)) {
|
|
199
|
+
clearTimeout(pending.timer);
|
|
200
|
+
pendingPermissionRequests.delete(id);
|
|
201
|
+
const resolved = JSON.stringify({ type: "plugin_permission_resolved", id });
|
|
202
|
+
for (const client of clients) {
|
|
203
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
204
|
+
try {
|
|
205
|
+
client.send(resolved);
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
/* dead connection */
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
pending.resolve({ ok: msg.ok === true, remember: msg.remember === true });
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
case "plugin_dom_consent": {
|
|
217
|
+
if (msg.granted === true) {
|
|
218
|
+
const pid = typeof msg.pluginId === "string" ? msg.pluginId.trim() : "";
|
|
219
|
+
if (!pid || !pluginMgr.isDomPlugin(pid) || pendingDomConsents.has(pid))
|
|
220
|
+
return true;
|
|
221
|
+
const id = randomUUID();
|
|
222
|
+
const timer = setTimeout(() => {
|
|
223
|
+
pendingDomConsents.delete(pid);
|
|
224
|
+
}, 120_000);
|
|
225
|
+
pendingDomConsents.set(pid, { id, pluginId: pid, recipients: new Set(pluginMgr.onlineClientIds()), timer });
|
|
226
|
+
const payload = JSON.stringify({ type: "plugin_dom_consent_request", id, pluginId: pid, from: clientId });
|
|
227
|
+
for (const client of clients) {
|
|
228
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
229
|
+
try {
|
|
230
|
+
client.send(payload);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
/* dead connection */
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
applyDomConsent(msg.pluginId, false);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
case "plugin_dom_consent_response": {
|
|
243
|
+
const id = typeof msg.id === "string" ? msg.id : "";
|
|
244
|
+
const pendingConsent = findDomConsentById(id);
|
|
245
|
+
if (pendingConsent && clientId && pendingConsent.recipients.has(clientId)) {
|
|
246
|
+
clearTimeout(pendingConsent.timer);
|
|
247
|
+
pendingDomConsents.delete(pendingConsent.pluginId);
|
|
248
|
+
if (msg.ok === true)
|
|
249
|
+
applyDomConsent(pendingConsent.pluginId, true);
|
|
250
|
+
}
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
case "plugin_path_revoke": {
|
|
254
|
+
const removed = pluginMgr.grants.revoke(typeof msg.pluginId === "string" ? msg.pluginId : undefined, typeof msg.path === "string" ? msg.path : undefined);
|
|
255
|
+
cs?.emitNotice?.("info", `已撤销 ${removed} 条插件目录授权`, `Revoked ${removed} plugin path grant(s)`);
|
|
256
|
+
pushPluginGrants();
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
case "plugin_permission_revoke": {
|
|
260
|
+
const family = msg.family === "net" || msg.family === "llm" ? msg.family : undefined;
|
|
261
|
+
const removed = pluginMgr.permGrants.revoke(typeof msg.pluginId === "string" ? msg.pluginId : undefined, family, typeof msg.host === "string" || typeof msg.model === "string"
|
|
262
|
+
? {
|
|
263
|
+
...(typeof msg.host === "string" ? { host: msg.host } : {}),
|
|
264
|
+
...(typeof msg.model === "string" ? { model: msg.model } : {}),
|
|
265
|
+
}
|
|
266
|
+
: undefined);
|
|
267
|
+
cs?.emitNotice?.("info", `已撤销 ${removed} 条能力授权`, `Revoked ${removed} permission grant(s)`);
|
|
268
|
+
pushPluginPermissions();
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
case "plugin_catalog_sync": {
|
|
272
|
+
const syncLang = () => cs?.getLang() ?? "en";
|
|
273
|
+
const requestId = String(msg.requestId ?? "");
|
|
274
|
+
void syncPluginCatalog(String(msg.source ?? ""), { install: msg.install === true, replace: msg.replace === true }, {
|
|
275
|
+
customCatalogPath: pluginMgr.customCatalogPath,
|
|
276
|
+
pluginsDir: join(dataDir, "plugins"),
|
|
277
|
+
installer: pluginInstaller,
|
|
278
|
+
afterWrite: () => (msg.install === true ? reloadPluginsAndPush(syncLang) : pluginMgr.pushCatalog()),
|
|
279
|
+
lang: syncLang,
|
|
280
|
+
workspaceRoot: cs?.cwd ?? cwd,
|
|
281
|
+
confirmInstall: (items) => confirmPluginInstallHelper(items),
|
|
282
|
+
}).then((r) => {
|
|
283
|
+
if (r.installRefused) {
|
|
284
|
+
cs?.emitNotice?.("warning", "目录已同步,但安装未获用户确认(拒绝或超时),未安装任何插件", "Catalog synced, but installation was not confirmed (denied or timed out) — nothing was installed");
|
|
285
|
+
}
|
|
286
|
+
send({
|
|
287
|
+
type: "plugin_catalog_sync_result",
|
|
288
|
+
requestId,
|
|
289
|
+
ok: r.ok,
|
|
290
|
+
...(r.error ? { error: r.error } : {}),
|
|
291
|
+
entries: pluginMgr.catalog(),
|
|
292
|
+
...(r.installed ? { installed: r.installed } : {}),
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
default:
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -29,9 +29,9 @@ import { basename, dirname, join, resolve, sep } from "node:path";
|
|
|
29
29
|
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
30
30
|
import { randomUUID } from "node:crypto";
|
|
31
31
|
import { homedir } from "node:os";
|
|
32
|
-
import { BgServerTracker } from "../bg-servers.js";
|
|
33
|
-
import { ClientStateStore, DEFAULT_RETRY_MAX_ATTEMPTS, normalizePathKey, normalizeToolWatchdogTimeoutMs, } from "../client-state.js";
|
|
34
|
-
import { normalizeUiLayout } from "../client-state.js";
|
|
32
|
+
import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "../bg-servers.js";
|
|
33
|
+
import { ClientStateStore, DEFAULT_RETRY_MAX_ATTEMPTS, normalizeBgCleanupMinutes, normalizePathKey, normalizeToolWatchdogTimeoutMs, settingsPresetToUi, } from "../client-state.js";
|
|
34
|
+
import { normalizeUiLayout, normalizeKeepRecentMessages, DEFAULT_KEEP_RECENT_MESSAGES } from "../client-state.js";
|
|
35
35
|
import { PLAN_MODE_SYSTEM_PROMPT } from "../plan-mode.js";
|
|
36
36
|
import { FilesService, workspacePath, desktopDirWire } from "../files-service.js";
|
|
37
37
|
import { QuiesceRejectedError } from "../agent-service.js";
|
|
@@ -51,6 +51,7 @@ import { DshStreamAccumulator, assistantMessageEventToUiMessage, toolResultEvent
|
|
|
51
51
|
import { firstUserText, findSessionFilesForCwd, readSessionLog, replayEventsToMessages, sessionLogPermission, sessionLogPreset, } from "./dsh-sessions.js";
|
|
52
52
|
import { generatePresetClones, PRESET_DEFAULT_ID } from "./preset-clones.js";
|
|
53
53
|
import { dshContextUsage, lastUsageFromEvents, normalizeDshUsage } from "./dsh-usage.js";
|
|
54
|
+
import { exportPresetVia, importPresetFromUrlVia, importPresetVia, packageVersion, pushPresetCatalogVia, sharePresetVia, } from "../preset-share.js";
|
|
54
55
|
const SNAPSHOT_INTERVAL_MS = 60;
|
|
55
56
|
/** 用户主目录(wire 格式):进程内不变,模块加载时求值一次(右栏 🏠)。 */
|
|
56
57
|
const HOME_WIRE = homedir().replace(/\\/g, "/");
|
|
@@ -129,6 +130,7 @@ const DEFAULT_SETTINGS = {
|
|
|
129
130
|
terminalBashIdleMs: 15_000,
|
|
130
131
|
terminalBashMaxForegroundMs: 60_000,
|
|
131
132
|
toolWatchdogTimeoutMs: 20 * 60_000,
|
|
133
|
+
bgAutoCleanupMin: 0,
|
|
132
134
|
editSoftEnabled: false,
|
|
133
135
|
questionnaireEnabled: true,
|
|
134
136
|
toolApprovalEnabled: true,
|
|
@@ -137,6 +139,7 @@ const DEFAULT_SETTINGS = {
|
|
|
137
139
|
thinkingWrap: false,
|
|
138
140
|
toolsWrap: true,
|
|
139
141
|
toolImagesEnabled: true,
|
|
142
|
+
keepRecentMessages: DEFAULT_KEEP_RECENT_MESSAGES,
|
|
140
143
|
disabledPlugins: [],
|
|
141
144
|
uiLayout: {},
|
|
142
145
|
reviewPrompt: "",
|
|
@@ -144,6 +147,8 @@ const DEFAULT_SETTINGS = {
|
|
|
144
147
|
defaultPermissionPreset: PERMISSION_DEFAULT_PRESET,
|
|
145
148
|
quickPhrases: [],
|
|
146
149
|
quickPhrasesEnabled: true,
|
|
150
|
+
promptTemplate: "",
|
|
151
|
+
promptOverrides: {},
|
|
147
152
|
};
|
|
148
153
|
// ---------------------------------------------------------------------------
|
|
149
154
|
// DshClientSession — 一个浏览器客户端
|
|
@@ -251,6 +256,7 @@ export class DshClientSession {
|
|
|
251
256
|
flushSnapshot: () => this.flushSnapshot(),
|
|
252
257
|
isDisposed: () => this.disposed,
|
|
253
258
|
pluginTasks: () => this.pluginBgTasksProvider?.() ?? [],
|
|
259
|
+
cleanupMinutes: () => Number(this.settings.bgAutoCleanupMin ?? 0),
|
|
254
260
|
});
|
|
255
261
|
}
|
|
256
262
|
static create(clientId, cwd, stateStore, dataDir, agentDir) {
|
|
@@ -278,6 +284,7 @@ export class DshClientSession {
|
|
|
278
284
|
terminalBashIdleMs: savedSettings.terminalBashIdleMs,
|
|
279
285
|
terminalBashMaxForegroundMs: savedSettings.terminalBashMaxForegroundMs ?? 60_000,
|
|
280
286
|
toolWatchdogTimeoutMs: savedSettings.toolWatchdogTimeoutMs ?? 20 * 60_000,
|
|
287
|
+
bgAutoCleanupMin: Number(savedSettings.bgAutoCleanupMin ?? 0),
|
|
281
288
|
editSoftEnabled: savedSettings.editSoftEnabled,
|
|
282
289
|
questionnaireEnabled: savedSettings.questionnaireEnabled ?? true,
|
|
283
290
|
toolApprovalEnabled: savedSettings.toolApprovalEnabled ?? true,
|
|
@@ -286,11 +293,14 @@ export class DshClientSession {
|
|
|
286
293
|
thinkingWrap: savedSettings.thinkingWrap,
|
|
287
294
|
toolsWrap: savedSettings.toolsWrap,
|
|
288
295
|
toolImagesEnabled: savedSettings.toolImagesEnabled ?? true,
|
|
296
|
+
keepRecentMessages: normalizeKeepRecentMessages(savedSettings.keepRecentMessages),
|
|
289
297
|
disabledPlugins: savedSettings.disabledPlugins ?? [],
|
|
290
298
|
uiLayout: normalizeUiLayout(savedSettings.uiLayout),
|
|
291
299
|
reviewPrompt: savedSettings.reviewPrompt,
|
|
292
300
|
quickPhrases: savedSettings.quickPhrases ?? [],
|
|
293
301
|
quickPhrasesEnabled: savedSettings.quickPhrasesEnabled ?? true,
|
|
302
|
+
promptTemplate: savedSettings.promptTemplate ?? "",
|
|
303
|
+
promptOverrides: savedSettings.promptOverrides ?? {},
|
|
294
304
|
defaultAgentPreset: savedSettings.defaultAgentPreset ?? PRESET_DEFAULT_ID,
|
|
295
305
|
defaultPermissionPreset: savedSettings.defaultPermissionPreset && PERMISSION_OFFERED.includes(savedSettings.defaultPermissionPreset)
|
|
296
306
|
? savedSettings.defaultPermissionPreset
|
|
@@ -1262,6 +1272,7 @@ export class DshClientSession {
|
|
|
1262
1272
|
permission: conv.permissionPreset ?? null,
|
|
1263
1273
|
queue: { steering: conv.queue.steering, followUp: conv.queue.followUp },
|
|
1264
1274
|
pendingQuestion: this.pendingQuestionForSnapshot(),
|
|
1275
|
+
actionSuggestions: null,
|
|
1265
1276
|
tools: [],
|
|
1266
1277
|
version: ++this.version,
|
|
1267
1278
|
piConfigured: this.isDshConfigured(),
|
|
@@ -2036,6 +2047,18 @@ export class DshClientSession {
|
|
|
2036
2047
|
this.bg.push();
|
|
2037
2048
|
return killed;
|
|
2038
2049
|
}
|
|
2050
|
+
/** 钉住 / 取消钉住(DSH 引擎同样有后台任务面板,行为与 pi 引擎一致)。 */
|
|
2051
|
+
setBackgroundKeep(port, keep) {
|
|
2052
|
+
return this.bg.setKeep(port, keep);
|
|
2053
|
+
}
|
|
2054
|
+
/** 手动「立即清理」(阈值策略与 pi 引擎同源:设置里的 bgAutoCleanupMin,关时兼底 30 分钟)。 */
|
|
2055
|
+
async cleanBackgroundLeftovers(minutesOverride) {
|
|
2056
|
+
const override = Number(minutesOverride);
|
|
2057
|
+
const policy = Number(this.settings.bgAutoCleanupMin ?? 0);
|
|
2058
|
+
const minutes = Number.isFinite(override) && override > 0 ? override : policy;
|
|
2059
|
+
const thresholdMs = (minutes > 0 ? minutes : BG_CLEANUP_FALLBACK_MIN) * 60_000;
|
|
2060
|
+
return this.bg.cleanStale(thresholdMs, { manual: true });
|
|
2061
|
+
}
|
|
2039
2062
|
// -----------------------------------------------------------------------
|
|
2040
2063
|
// 会话列表 / 切换 / 删除
|
|
2041
2064
|
// -----------------------------------------------------------------------
|
|
@@ -2630,6 +2653,9 @@ export class DshClientSession {
|
|
|
2630
2653
|
toolWatchdogTimeoutMs: this.settings.toolWatchdogTimeoutMs,
|
|
2631
2654
|
// DSH 引擎无 customTool 注册面(工具来自 shipped preset),read 目录覆盖面不存在。
|
|
2632
2655
|
readDirEnabled: true,
|
|
2656
|
+
bgAutoCleanupMin: Number(this.settings.bgAutoCleanupMin ?? 0),
|
|
2657
|
+
// DSH 无 pi 工具注册面,不适用延迟加载;保协议完整。
|
|
2658
|
+
toolLazyLoading: true,
|
|
2633
2659
|
editSoftEnabled: this.settings.editSoftEnabled,
|
|
2634
2660
|
// DSH 无独立重试配置(pi 引擎才暴露),保持默认。
|
|
2635
2661
|
retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
@@ -2646,6 +2672,7 @@ export class DshClientSession {
|
|
|
2646
2672
|
thinkingWrap: this.settings.thinkingWrap,
|
|
2647
2673
|
toolsWrap: this.settings.toolsWrap,
|
|
2648
2674
|
toolImagesEnabled: this.settings.toolImagesEnabled,
|
|
2675
|
+
keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
|
|
2649
2676
|
// DSH 无 skill 全文注入概念,给空保协议完整。
|
|
2650
2677
|
skillsFullText: [],
|
|
2651
2678
|
visionBridgeEnabled: false,
|
|
@@ -2663,8 +2690,10 @@ export class DshClientSession {
|
|
|
2663
2690
|
reviewDisabledSkills: [],
|
|
2664
2691
|
disabledPlugins: this.settings.disabledPlugins,
|
|
2665
2692
|
uiLayout: normalizeUiLayout(this.settings.uiLayout),
|
|
2666
|
-
promptTemplate: "",
|
|
2667
|
-
promptOverrides: {},
|
|
2693
|
+
promptTemplate: this.settings.promptTemplate ?? "",
|
|
2694
|
+
promptOverrides: this.settings.promptOverrides ?? {},
|
|
2695
|
+
// DSH 无 pi 工具注册表面,逐工具文案覆盖不适用;保协议完整。
|
|
2696
|
+
toolPromptOverrides: {},
|
|
2668
2697
|
effectiveSystemPrompt: this.settings.customSystemPrompt,
|
|
2669
2698
|
promptSourceDefaults: {},
|
|
2670
2699
|
// DSH 引擎不接标准 pi 的 customTool 工具 schema(走 goal-rpc),此处给空。
|
|
@@ -2675,7 +2704,7 @@ export class DshClientSession {
|
|
|
2675
2704
|
skills: this.skillsCache,
|
|
2676
2705
|
reviewSkills: [],
|
|
2677
2706
|
extensions: [],
|
|
2678
|
-
presets: this.stateStore.getPresets(this.clientId),
|
|
2707
|
+
presets: this.stateStore.getPresets(this.clientId).map(settingsPresetToUi),
|
|
2679
2708
|
markersEnabled: true,
|
|
2680
2709
|
disabledMarkers: [],
|
|
2681
2710
|
markers: [],
|
|
@@ -2696,6 +2725,10 @@ export class DshClientSession {
|
|
|
2696
2725
|
this.settings.promptMode = partial.promptMode;
|
|
2697
2726
|
if (partial.customSystemPrompt !== undefined)
|
|
2698
2727
|
this.settings.customSystemPrompt = partial.customSystemPrompt;
|
|
2728
|
+
if (partial.promptTemplate !== undefined)
|
|
2729
|
+
this.settings.promptTemplate = partial.promptTemplate;
|
|
2730
|
+
if (partial.promptOverrides !== undefined)
|
|
2731
|
+
this.settings.promptOverrides = partial.promptOverrides;
|
|
2699
2732
|
if (partial.disabledSkills !== undefined)
|
|
2700
2733
|
this.settings.disabledSkills = partial.disabledSkills;
|
|
2701
2734
|
if (partial.disabledExtensions !== undefined)
|
|
@@ -2710,6 +2743,8 @@ export class DshClientSession {
|
|
|
2710
2743
|
this.settings.terminalBashMaxForegroundMs = partial.terminalBashMaxForegroundMs;
|
|
2711
2744
|
if (partial.toolWatchdogTimeoutMs !== undefined)
|
|
2712
2745
|
this.settings.toolWatchdogTimeoutMs = normalizeToolWatchdogTimeoutMs(partial.toolWatchdogTimeoutMs);
|
|
2746
|
+
if (partial.bgAutoCleanupMin !== undefined)
|
|
2747
|
+
this.settings.bgAutoCleanupMin = normalizeBgCleanupMinutes(partial.bgAutoCleanupMin);
|
|
2713
2748
|
if (partial.editSoftEnabled !== undefined)
|
|
2714
2749
|
this.settings.editSoftEnabled = partial.editSoftEnabled;
|
|
2715
2750
|
if (partial.questionnaireEnabled !== undefined)
|
|
@@ -2726,6 +2761,8 @@ export class DshClientSession {
|
|
|
2726
2761
|
this.settings.toolsWrap = partial.toolsWrap;
|
|
2727
2762
|
if (partial.toolImagesEnabled !== undefined)
|
|
2728
2763
|
this.settings.toolImagesEnabled = partial.toolImagesEnabled;
|
|
2764
|
+
if (partial.keepRecentMessages !== undefined)
|
|
2765
|
+
this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
|
|
2729
2766
|
if (partial.disabledPlugins !== undefined)
|
|
2730
2767
|
this.settings.disabledPlugins = partial.disabledPlugins;
|
|
2731
2768
|
if (partial.uiLayout !== undefined)
|
|
@@ -2764,12 +2801,15 @@ export class DshClientSession {
|
|
|
2764
2801
|
thinkingWrap: this.settings.thinkingWrap,
|
|
2765
2802
|
toolsWrap: this.settings.toolsWrap,
|
|
2766
2803
|
toolImagesEnabled: this.settings.toolImagesEnabled,
|
|
2804
|
+
keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
|
|
2767
2805
|
disabledPlugins: this.settings.disabledPlugins,
|
|
2768
2806
|
uiLayout: normalizeUiLayout(this.settings.uiLayout),
|
|
2769
2807
|
reviewPrompt: this.settings.reviewPrompt,
|
|
2770
2808
|
quickPhrases: this.settings.quickPhrases,
|
|
2771
2809
|
quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
|
|
2772
2810
|
defaultAgentPreset: this.settings.defaultAgentPreset,
|
|
2811
|
+
promptTemplate: this.settings.promptTemplate ?? "",
|
|
2812
|
+
promptOverrides: this.settings.promptOverrides ?? {},
|
|
2773
2813
|
});
|
|
2774
2814
|
// 仅系统提示词变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
|
|
2775
2815
|
// 其他设置(开关/隐藏插件等)只存不回写运行时。
|
|
@@ -3127,13 +3167,13 @@ export class DshClientSession {
|
|
|
3127
3167
|
});
|
|
3128
3168
|
return;
|
|
3129
3169
|
}
|
|
3130
|
-
this.settings.promptMode = preset.promptMode;
|
|
3131
|
-
this.settings.customSystemPrompt = preset.customSystemPrompt;
|
|
3170
|
+
this.settings.promptMode = preset.promptMode === "replace" ? "replace" : "append";
|
|
3171
|
+
this.settings.customSystemPrompt = preset.customSystemPrompt ?? "";
|
|
3132
3172
|
this.settings.disabledSkills = preset.disabledSkills ?? [];
|
|
3133
3173
|
this.settings.disabledExtensions = preset.disabledExtensions ?? [];
|
|
3134
|
-
this.settings.terminalToolsEnabled = preset.terminalToolsEnabled;
|
|
3135
|
-
this.settings.terminalBash = preset.terminalBash;
|
|
3136
|
-
this.settings.terminalBashIdleMs = preset.terminalBashIdleMs;
|
|
3174
|
+
this.settings.terminalToolsEnabled = preset.terminalToolsEnabled ?? this.settings.terminalToolsEnabled;
|
|
3175
|
+
this.settings.terminalBash = preset.terminalBash ?? this.settings.terminalBash;
|
|
3176
|
+
this.settings.terminalBashIdleMs = preset.terminalBashIdleMs ?? this.settings.terminalBashIdleMs;
|
|
3137
3177
|
this.settings.terminalBashMaxForegroundMs =
|
|
3138
3178
|
preset.terminalBashMaxForegroundMs ?? this.settings.terminalBashMaxForegroundMs;
|
|
3139
3179
|
this.settings.editSoftEnabled = preset.editSoftEnabled ?? this.settings.editSoftEnabled;
|
|
@@ -3151,6 +3191,7 @@ export class DshClientSession {
|
|
|
3151
3191
|
thinkingWrap: this.settings.thinkingWrap,
|
|
3152
3192
|
toolsWrap: this.settings.toolsWrap,
|
|
3153
3193
|
toolImagesEnabled: this.settings.toolImagesEnabled,
|
|
3194
|
+
keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
|
|
3154
3195
|
disabledPlugins: this.settings.disabledPlugins,
|
|
3155
3196
|
uiLayout: normalizeUiLayout(this.settings.uiLayout),
|
|
3156
3197
|
reviewPrompt: this.settings.reviewPrompt,
|
|
@@ -3164,6 +3205,70 @@ export class DshClientSession {
|
|
|
3164
3205
|
this.stateStore.savePresets(this.clientId, presets.filter((p) => p.name !== name));
|
|
3165
3206
|
this.pushSettings();
|
|
3166
3207
|
}
|
|
3208
|
+
/* -----------------------------------------------------------------------
|
|
3209
|
+
* 预设分享(server/preset-share.ts)—— 与 pi 引擎同一份编排,只换适配层。
|
|
3210
|
+
* DSH 的预设存储/应用语义不同,所以把「取/存/应用」按 DSH 的做法接上。
|
|
3211
|
+
* --------------------------------------------------------------------- */
|
|
3212
|
+
/** 分享编排需要的最小能力集合(DSH 侧)。 */
|
|
3213
|
+
sharePort() {
|
|
3214
|
+
return {
|
|
3215
|
+
lang: () => this.getLang(),
|
|
3216
|
+
appVersion: () => packageVersion(),
|
|
3217
|
+
presets: () => this.stateStore.getPresets(this.clientId),
|
|
3218
|
+
currentSettings: () => {
|
|
3219
|
+
const s = this.settings;
|
|
3220
|
+
// DSH 的预设记录字段与 ClientSettings 不完全一致(没有 promptTemplate/
|
|
3221
|
+
// promptOverrides 等),导出时按预设形状给默认值(应用侧只读它认识的)。
|
|
3222
|
+
return {
|
|
3223
|
+
promptMode: s.promptMode,
|
|
3224
|
+
customSystemPrompt: s.customSystemPrompt,
|
|
3225
|
+
promptTemplate: "",
|
|
3226
|
+
promptOverrides: {},
|
|
3227
|
+
disabledSkills: [...(s.disabledSkills ?? [])],
|
|
3228
|
+
disabledExtensions: [...(s.disabledExtensions ?? [])],
|
|
3229
|
+
disabledAgentTools: [],
|
|
3230
|
+
disabledPluginTools: [],
|
|
3231
|
+
terminalToolsEnabled: s.terminalToolsEnabled,
|
|
3232
|
+
terminalBash: s.terminalBash,
|
|
3233
|
+
terminalBashIdleMs: s.terminalBashIdleMs,
|
|
3234
|
+
terminalBashMaxForegroundMs: s.terminalBashMaxForegroundMs,
|
|
3235
|
+
editSoftEnabled: s.editSoftEnabled,
|
|
3236
|
+
skillsFullText: [],
|
|
3237
|
+
reviewPrompt: s.reviewPrompt ?? "",
|
|
3238
|
+
reviewDisabledSkills: [],
|
|
3239
|
+
};
|
|
3240
|
+
},
|
|
3241
|
+
upsertPreset: (preset) => {
|
|
3242
|
+
const presets = this.stateStore.getPresets(this.clientId);
|
|
3243
|
+
this.stateStore.savePresets(this.clientId, presets.some((p) => p.name === preset.name)
|
|
3244
|
+
? presets.map((p) => (p.name === preset.name ? preset : p))
|
|
3245
|
+
: [...presets, preset]);
|
|
3246
|
+
},
|
|
3247
|
+
applyPreset: (name) => this.applyPreset(name),
|
|
3248
|
+
pushSettings: () => this.pushSettings(),
|
|
3249
|
+
emit: (msg) => this.emit(msg),
|
|
3250
|
+
};
|
|
3251
|
+
}
|
|
3252
|
+
/** 导出预设/当前设置为可分享的 JSON(服务端 preset-share.ts)。 */
|
|
3253
|
+
async exportPreset(msg) {
|
|
3254
|
+
exportPresetVia(this.sharePort(), msg);
|
|
3255
|
+
}
|
|
3256
|
+
/** 解析导入的预设 JSON(dryRun = 只预览)。 */
|
|
3257
|
+
async importPreset(msg) {
|
|
3258
|
+
await importPresetVia(this.sharePort(), msg);
|
|
3259
|
+
}
|
|
3260
|
+
/** 按网址导入预设(服务端抓取)。 */
|
|
3261
|
+
async importPresetFromUrl(msg) {
|
|
3262
|
+
await importPresetFromUrlVia(this.sharePort(), msg);
|
|
3263
|
+
}
|
|
3264
|
+
/** 拉社区共享预设目录。 */
|
|
3265
|
+
async pushPresetCatalog(msg) {
|
|
3266
|
+
await pushPresetCatalogVia(this.sharePort(), msg);
|
|
3267
|
+
}
|
|
3268
|
+
/** 一键分享预设到社区共享仓库。 */
|
|
3269
|
+
async sharePreset(msg) {
|
|
3270
|
+
await sharePresetVia(this.sharePort(), msg);
|
|
3271
|
+
}
|
|
3167
3272
|
// -----------------------------------------------------------------------
|
|
3168
3273
|
// 子代理模板(DSH 引擎无子代理概念 —— 设置面板分区由前端 isDsh 隐藏)
|
|
3169
3274
|
// -----------------------------------------------------------------------
|
|
@@ -3990,8 +4095,14 @@ export class DshClientSession {
|
|
|
3990
4095
|
const newSessionId = `fork-${randomUUID().slice(0, 12)}`;
|
|
3991
4096
|
const fresh = this.addConversation(newSessionId, this.cwd, false);
|
|
3992
4097
|
// 回放编辑点之前的消息(作为会话初始上下文:DSH 无 seed 机制,v1 用
|
|
3993
|
-
//
|
|
3994
|
-
|
|
4098
|
+
// 简化——直接把历史作为一条提示词说明附上)。跳过紧挨在当前提问前面的前置附件卡片。
|
|
4099
|
+
let cutIdx = idx;
|
|
4100
|
+
while (cutIdx > 0 &&
|
|
4101
|
+
conv.messages[cutIdx - 1]?.role === "custom" &&
|
|
4102
|
+
conv.messages[cutIdx - 1]?.customType === "file") {
|
|
4103
|
+
cutIdx--;
|
|
4104
|
+
}
|
|
4105
|
+
const head = conv.messages.slice(0, cutIdx);
|
|
3995
4106
|
// 把编辑前的对话内容写进新会话的 prompt(尽力保留上下文)。
|
|
3996
4107
|
const contextNote = head
|
|
3997
4108
|
.map((m) => {
|
|
@@ -4238,6 +4349,7 @@ export class DshAgentService {
|
|
|
4238
4349
|
if (conv)
|
|
4239
4350
|
return {
|
|
4240
4351
|
clientId,
|
|
4352
|
+
convId: conv.id,
|
|
4241
4353
|
title: conv.title,
|
|
4242
4354
|
cwd: conv.cwd,
|
|
4243
4355
|
isStreaming: conv.isStreaming,
|
|
@@ -32,11 +32,11 @@ import { EDIT_SOFT_TOOL_NAME } from "./tool-manager.js";
|
|
|
32
32
|
export const SOFT_EDIT_TOOL_NAME = EDIT_SOFT_TOOL_NAME;
|
|
33
33
|
const replaceEditSchema = Type.Object({
|
|
34
34
|
oldText: Type.String({
|
|
35
|
-
description: "Text to replace. Loose matching:
|
|
36
|
-
"
|
|
35
|
+
description: "Text to replace. Loose matching: each non-empty line must match by trimmed content, so leading-indentation (spaces/tabs) differences are ignored. " +
|
|
36
|
+
"Prefer whole lines/blocks.",
|
|
37
37
|
}),
|
|
38
38
|
newText: Type.String({
|
|
39
|
-
description: "Replacement text (written verbatim
|
|
39
|
+
description: "Replacement text (written verbatim).",
|
|
40
40
|
}),
|
|
41
41
|
}, {});
|
|
42
42
|
const editSoftSchema = Type.Object({
|
|
@@ -44,8 +44,8 @@ const editSoftSchema = Type.Object({
|
|
|
44
44
|
description: "Path of the file to edit (relative or absolute).",
|
|
45
45
|
}),
|
|
46
46
|
edits: Type.Array(replaceEditSchema, {
|
|
47
|
-
description: "One or more targeted replacements
|
|
48
|
-
"do not include overlapping/nested edits
|
|
47
|
+
description: "One or more targeted replacements, matched against the original file (not incrementally); " +
|
|
48
|
+
"do not include overlapping/nested edits.",
|
|
49
49
|
}),
|
|
50
50
|
}, {});
|
|
51
51
|
function isSingleEditInput(value) {
|
|
@@ -304,14 +304,12 @@ export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
|
304
304
|
return defineTool({
|
|
305
305
|
name: SOFT_EDIT_TOOL_NAME,
|
|
306
306
|
label: "Edit (indentation-insensitive)",
|
|
307
|
-
description: "Edit a single file with text replacement tolerant of indentation: oldText
|
|
308
|
-
"
|
|
309
|
-
promptSnippet: "edit a file
|
|
307
|
+
description: "Edit a single file with text replacement tolerant of indentation: oldText matches by trimmed line content, " +
|
|
308
|
+
"so leading-whitespace drift (common in JS/JSON) does not fail the edit.",
|
|
309
|
+
promptSnippet: "edit a file when whitespace/indentation makes the built-in edit fail",
|
|
310
310
|
promptGuidelines: [
|
|
311
|
-
"Use edit_soft when edit
|
|
312
|
-
"
|
|
313
|
-
"newText is written verbatim — the indentation you provide is the final indentation in the file",
|
|
314
|
-
"Keep edits[].oldText as small as possible while still being unique; " + "merge nearby changes into one edit",
|
|
311
|
+
"Use edit_soft when edit rejects oldText on an indentation/spacing mismatch",
|
|
312
|
+
"Keep edits[].oldText as small as possible while still being unique; merge nearby changes into one edit",
|
|
315
313
|
],
|
|
316
314
|
parameters: editSoftSchema,
|
|
317
315
|
prepareArguments: prepareSoftEditArguments,
|