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.
Files changed (82) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/README.md +46 -44
  3. package/README.zh-CN.md +41 -39
  4. package/bin/pi-web-ui.mjs +17 -19
  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 +9884 -12815
  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 +104 -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 +38 -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 +30 -5
  23. package/dist/server/dsh/runtime/goal-rpc.mjs +5 -1
  24. package/dist/server/goal-evidence.js +9 -2
  25. package/dist/server/goal-service.js +1 -1
  26. package/dist/server/hashline-engine.js +1 -1
  27. package/dist/server/index.js +191 -969
  28. package/dist/server/left-panel-running.js +115 -0
  29. package/dist/server/lsp-tool.js +40 -12
  30. package/dist/server/markers-list-tool.js +34 -0
  31. package/dist/server/market-service.js +277 -0
  32. package/dist/server/mcp-bridge.js +137 -30
  33. package/dist/server/mcp-hot-reload.js +84 -27
  34. package/dist/server/mcp-manager.js +215 -0
  35. package/dist/server/message-entry-resolver.js +32 -0
  36. package/dist/server/orphan-manager.js +44 -0
  37. package/dist/server/persona-chain.js +63 -0
  38. package/dist/server/plan-mode.js +2 -0
  39. package/dist/server/plan-update-tool.js +96 -0
  40. package/dist/server/plugin-api-catalog.js +20 -0
  41. package/dist/server/plugin-facilities.js +13 -3
  42. package/dist/server/plugin-installer.js +6 -1
  43. package/dist/server/plugin-ui-slots.js +39 -0
  44. package/dist/server/plugins.js +72 -38
  45. package/dist/server/preset-fields.js +35 -0
  46. package/dist/server/preset-share.js +9 -0
  47. package/dist/server/process-utils.js +30 -0
  48. package/dist/server/prompt-assembler.js +80 -0
  49. package/dist/server/protocol-version.js +1 -1
  50. package/dist/server/scm-commitmsg.js +74 -0
  51. package/dist/server/serialize.js +97 -7
  52. package/dist/server/session-branch.js +367 -0
  53. package/dist/server/session-parser.js +235 -0
  54. package/dist/server/session-search.js +158 -0
  55. package/dist/server/settings-service.js +28 -1
  56. package/dist/server/skill-content-filler.js +33 -0
  57. package/dist/server/subagent-handoff.js +18 -0
  58. package/dist/server/subagent-helpers.js +88 -0
  59. package/dist/server/terminals.js +155 -58
  60. package/dist/server/tool-guards.js +527 -0
  61. package/dist/server/tool-host-factories.js +217 -0
  62. package/dist/server/tool-manager.js +30 -5
  63. package/dist/server/wait-subscription-scan.js +46 -1
  64. package/dist/server/workspace-snapshot.js +18 -0
  65. package/extensions/webui.ts +90 -24
  66. package/package.json +1 -1
  67. package/plugin-sdk/README.md +17 -0
  68. package/plugin-sdk/index.d.ts +17 -0
  69. package/plugin-sdk/index.mjs +5 -0
  70. package/plugins/catalog.json +20 -0
  71. package/themes/aetheris.css +3 -1
  72. package/themes/translucent.css +8 -1
  73. package/themes/transparent.css +9 -1
  74. package/themes/zhupi-dark.css +3 -14
  75. package/themes/zhupi.css +2 -16
  76. package/web/dist/assets/{TerminalPanel-C3I1Mc-C.js → TerminalPanel-CYGOzbPT.js} +1 -1
  77. package/web/dist/assets/index-CP71PHb6.js +680 -0
  78. package/web/dist/assets/index-ytRwL6j0.css +1 -0
  79. package/web/dist/index.html +2 -2
  80. package/web/dist/sw.js +1 -1
  81. package/web/dist/assets/index-B-E2EM_0.css +0 -1
  82. package/web/dist/assets/index-BYumAaGi.js +0 -379
@@ -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
+ }
@@ -31,7 +31,7 @@ import { randomUUID } from "node:crypto";
31
31
  import { homedir } from "node:os";
32
32
  import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "../bg-servers.js";
33
33
  import { ClientStateStore, DEFAULT_RETRY_MAX_ATTEMPTS, normalizeBgCleanupMinutes, normalizePathKey, normalizeToolWatchdogTimeoutMs, settingsPresetToUi, } from "../client-state.js";
34
- import { normalizeUiLayout } 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";
@@ -139,6 +139,7 @@ const DEFAULT_SETTINGS = {
139
139
  thinkingWrap: false,
140
140
  toolsWrap: true,
141
141
  toolImagesEnabled: true,
142
+ keepRecentMessages: DEFAULT_KEEP_RECENT_MESSAGES,
142
143
  disabledPlugins: [],
143
144
  uiLayout: {},
144
145
  reviewPrompt: "",
@@ -292,6 +293,7 @@ export class DshClientSession {
292
293
  thinkingWrap: savedSettings.thinkingWrap,
293
294
  toolsWrap: savedSettings.toolsWrap,
294
295
  toolImagesEnabled: savedSettings.toolImagesEnabled ?? true,
296
+ keepRecentMessages: normalizeKeepRecentMessages(savedSettings.keepRecentMessages),
295
297
  disabledPlugins: savedSettings.disabledPlugins ?? [],
296
298
  uiLayout: normalizeUiLayout(savedSettings.uiLayout),
297
299
  reviewPrompt: savedSettings.reviewPrompt,
@@ -1391,6 +1393,7 @@ export class DshClientSession {
1391
1393
  continue;
1392
1394
  list.push({
1393
1395
  id: conv.id,
1396
+ sessionId: conv.sessionId,
1394
1397
  title: conv.title,
1395
1398
  cwd: conv.cwd,
1396
1399
  messageCount: conv.messages.length,
@@ -2091,6 +2094,7 @@ export class DshClientSession {
2091
2094
  const { events } = readSessionLog(file);
2092
2095
  summaries.push({
2093
2096
  path: file,
2097
+ sessionId,
2094
2098
  name: sessionId,
2095
2099
  firstMessage: firstUserText(events, this.getLang()),
2096
2100
  messageCount: events.filter((e) => e.type === "user/message" || e.type === "assistant/message" || e.type === "tool/result").length,
@@ -2230,17 +2234,30 @@ export class DshClientSession {
2230
2234
  });
2231
2235
  }
2232
2236
  /** 切换会话:读 JSONL 回放 → 新建 conversation(同一 sessionId 续聊)。 */
2233
- async switchSession(path) {
2237
+ async switchSession(path, wantSessionId) {
2234
2238
  try {
2235
- const abs = resolve(path);
2236
- const sessionId = basename(dirname(abs));
2239
+ const explicitSid = wantSessionId?.trim() ?? "";
2240
+ const sessionId = explicitSid || basename(dirname(resolve(path)));
2237
2241
  // 同一 sessionId 已在运行 → 直接切过去。
2238
2242
  for (const conv of this.convs.values()) {
2239
- if (conv.sessionId === sessionId) {
2243
+ if (conv.sessionId === sessionId || conv.id === sessionId) {
2240
2244
  await this.switchConversation(conv.id);
2241
2245
  return;
2242
2246
  }
2243
2247
  }
2248
+ if (!path.trim() && explicitSid) {
2249
+ const candidateFile = join(this.sessionRoot, explicitSid, "session.jsonl");
2250
+ if (!existsSync(candidateFile)) {
2251
+ this.emit({
2252
+ type: "notice",
2253
+ level: "warning",
2254
+ text: `未找到会话:${explicitSid}`,
2255
+ textEn: `Session not found: ${explicitSid}`,
2256
+ });
2257
+ this.flushSnapshot(true);
2258
+ return;
2259
+ }
2260
+ }
2244
2261
  // issue #145:同 pi 引擎 —— 别处正在跑同一 sessionId 时不建第二个持有者。
2245
2262
  const owner = this.findSessionOwnerById?.(sessionId);
2246
2263
  if (owner && owner.isStreaming) {
@@ -2654,6 +2671,8 @@ export class DshClientSession {
2654
2671
  bgAutoCleanupMin: Number(this.settings.bgAutoCleanupMin ?? 0),
2655
2672
  // DSH 无 pi 工具注册面,不适用延迟加载;保协议完整。
2656
2673
  toolLazyLoading: true,
2674
+ codemodeMode: "on",
2675
+ codemodeInlineBudget: 3000,
2657
2676
  editSoftEnabled: this.settings.editSoftEnabled,
2658
2677
  // DSH 无独立重试配置(pi 引擎才暴露),保持默认。
2659
2678
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
@@ -2670,6 +2689,7 @@ export class DshClientSession {
2670
2689
  thinkingWrap: this.settings.thinkingWrap,
2671
2690
  toolsWrap: this.settings.toolsWrap,
2672
2691
  toolImagesEnabled: this.settings.toolImagesEnabled,
2692
+ keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
2673
2693
  // DSH 无 skill 全文注入概念,给空保协议完整。
2674
2694
  skillsFullText: [],
2675
2695
  visionBridgeEnabled: false,
@@ -2758,6 +2778,8 @@ export class DshClientSession {
2758
2778
  this.settings.toolsWrap = partial.toolsWrap;
2759
2779
  if (partial.toolImagesEnabled !== undefined)
2760
2780
  this.settings.toolImagesEnabled = partial.toolImagesEnabled;
2781
+ if (partial.keepRecentMessages !== undefined)
2782
+ this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
2761
2783
  if (partial.disabledPlugins !== undefined)
2762
2784
  this.settings.disabledPlugins = partial.disabledPlugins;
2763
2785
  if (partial.uiLayout !== undefined)
@@ -2796,6 +2818,7 @@ export class DshClientSession {
2796
2818
  thinkingWrap: this.settings.thinkingWrap,
2797
2819
  toolsWrap: this.settings.toolsWrap,
2798
2820
  toolImagesEnabled: this.settings.toolImagesEnabled,
2821
+ keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
2799
2822
  disabledPlugins: this.settings.disabledPlugins,
2800
2823
  uiLayout: normalizeUiLayout(this.settings.uiLayout),
2801
2824
  reviewPrompt: this.settings.reviewPrompt,
@@ -3185,6 +3208,7 @@ export class DshClientSession {
3185
3208
  thinkingWrap: this.settings.thinkingWrap,
3186
3209
  toolsWrap: this.settings.toolsWrap,
3187
3210
  toolImagesEnabled: this.settings.toolImagesEnabled,
3211
+ keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
3188
3212
  disabledPlugins: this.settings.disabledPlugins,
3189
3213
  uiLayout: normalizeUiLayout(this.settings.uiLayout),
3190
3214
  reviewPrompt: this.settings.reviewPrompt,
@@ -4342,6 +4366,7 @@ export class DshAgentService {
4342
4366
  if (conv)
4343
4367
  return {
4344
4368
  clientId,
4369
+ convId: conv.id,
4345
4370
  title: conv.title,
4346
4371
  cwd: conv.cwd,
4347
4372
  isStreaming: conv.isStreaming,
@@ -923,7 +923,11 @@ class DshGoalJsonRpcServer extends HarnessSdkJsonRpcServer {
923
923
  }
924
924
  this.questionBridge.pending = null;
925
925
  if (params?.cancelled) {
926
- pending.reject(new Error("用户取消了提问"));
926
+ const reason =
927
+ typeof params?.cancelReason === "string" && params.cancelReason.trim()
928
+ ? `(附言:${params.cancelReason.trim()})`
929
+ : "";
930
+ pending.reject(new Error(`用户取消了提问${reason}`));
927
931
  } else {
928
932
  const answers = Array.isArray(params?.answers) ? params.answers : [];
929
933
  pending.resolve({ answers });
@@ -25,6 +25,13 @@ function isRecord(v) {
25
25
  return typeof v === "object" && v !== null;
26
26
  }
27
27
  /** 压成一行并封顶(提示是给人/模型扫的,不做换行)。 */
28
+ /** 高危命中前缀:同一命令里的多处命中逐条列出(去重标签,#578)。 */
29
+ function dangerPrefix(hits) {
30
+ if (hits.length === 0)
31
+ return "";
32
+ const labels = [...new Set(hits.map((h) => h.label))];
33
+ return `⚠️ [${labels.join(" / ")}] `;
34
+ }
28
35
  function oneLine(v, max = 120) {
29
36
  if (typeof v !== "string")
30
37
  return "";
@@ -95,7 +102,7 @@ export function collectToolEvidence(messages, opts = {}) {
95
102
  if (m.role === "bashExecution") {
96
103
  const cmd = typeof m.command === "string" ? m.command : "";
97
104
  const dangerHits = checkBashCommandDanger(cmd);
98
- const prefix = dangerHits.length > 0 ? `⚠️ [${dangerHits[0].label}] ` : "";
105
+ const prefix = dangerPrefix(dangerHits);
99
106
  out.push({
100
107
  tool: "bash",
101
108
  hint: `${prefix}${oneLine(m.command)}`,
@@ -114,7 +121,7 @@ export function collectToolEvidence(messages, opts = {}) {
114
121
  if (effectiveTool === "bash" && hint) {
115
122
  const dangerHits = checkBashCommandDanger(hint);
116
123
  if (dangerHits.length > 0) {
117
- hint = `⚠️ [${dangerHits[0].label}] ${hint}`;
124
+ hint = `${dangerPrefix(dangerHits)}${hint}`;
118
125
  }
119
126
  }
120
127
  out.push({
@@ -1163,7 +1163,7 @@ export class GoalService {
1163
1163
  async stopAllGoals() {
1164
1164
  let stopped = 0;
1165
1165
  // 快照迭代:await stopDelegated 期间,循环退出的回调可能增删这张表。
1166
- for (const convId of [...this.delegatedLoops.keys()]) {
1166
+ for (const convId of Array.from(this.delegatedLoops.keys())) {
1167
1167
  const conv = this.host.getConv(convId);
1168
1168
  if (!conv)
1169
1169
  continue;
@@ -333,7 +333,7 @@ export const globalSnapshotStore = new HashlineSnapshotStore();
333
333
  *
334
334
  * 核心逻辑:若磁盘文件的改动未侵入 targetHunks 所在的锚点行,则将锚点行映射到最新文件的对应行,安全完成合并。
335
335
  */
336
- export function tryRecoverEdits(baseText, currentText, hunks, filePath) {
336
+ export function tryRecoverEdits(baseText, currentText, hunks, _filePath) {
337
337
  const baseLines = normalizeLineEndings(baseText).split("\n");
338
338
  const curLines = normalizeLineEndings(currentText).split("\n");
339
339
  // 若内容完全相同,无需恢复