pi-web-ui 0.106.0 → 0.108.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 (59) hide show
  1. package/CHANGELOG.md +77 -11
  2. package/README.zh-TW.md +2 -2
  3. package/dist/server/agent-formatters.js +19 -4
  4. package/dist/server/agent-service.js +33 -16
  5. package/dist/server/bg-servers.js +205 -53
  6. package/dist/server/client-state.js +6 -2
  7. package/dist/server/dispatch-domain-handlers.js +2 -0
  8. package/dist/server/dsh/dsh-agent-service.js +24 -10
  9. package/dist/server/durable/durable-agent-service.js +153 -0
  10. package/dist/server/durable/durable-capabilities.js +11 -0
  11. package/dist/server/durable/durable-driver.js +481 -0
  12. package/dist/server/durable/durable-loader.js +38 -0
  13. package/dist/server/durable/durable-models.js +283 -0
  14. package/dist/server/durable/durable-storage.js +42 -0
  15. package/dist/server/durable/durable-tools.js +45 -0
  16. package/dist/server/durable/index.js +8 -0
  17. package/dist/server/engine-capabilities.js +20 -1
  18. package/dist/server/engine-probe.js +156 -8
  19. package/dist/server/files-service.js +15 -1
  20. package/dist/server/global-loader.js +335 -0
  21. package/dist/server/index.js +127 -17
  22. package/dist/server/managed.js +2 -0
  23. package/dist/server/marker-service.js +5 -19
  24. package/dist/server/markers/index.js +1 -3
  25. package/dist/server/model-admin.js +61 -10
  26. package/dist/server/model-resolver.js +91 -3
  27. package/dist/server/plugins.js +18 -1
  28. package/dist/server/preset-fields.js +14 -0
  29. package/dist/server/preset-share.js +2 -0
  30. package/dist/server/process-utils.js +114 -12
  31. package/dist/server/protocol-version.js +1 -1
  32. package/dist/server/sdk-origin.js +2 -2
  33. package/dist/server/serialize.js +1 -1
  34. package/dist/server/settings-service.js +4 -0
  35. package/dist/server/text-sniff.js +2 -0
  36. package/dist/server/tool-manager.js +3 -19
  37. package/dist/server/universal/driver-base.js +4 -0
  38. package/dist/server/universal/drivers/claude-code.js +3 -2
  39. package/dist/server/universal/universal-service.js +19 -2
  40. package/dist/server/universal/universal-session.js +63 -7
  41. package/dist/server/update-check.js +20 -8
  42. package/package.json +2 -1
  43. package/plugins/catalog.json +13 -2
  44. package/themes/dark-teal.css +0 -1
  45. package/themes/flow-light.css +1085 -0
  46. package/themes/flow.css +1094 -0
  47. package/themes/wallpaper-flow.css +1158 -0
  48. package/themes/wallpaper-obsidian.css +50 -0
  49. package/themes/zhujian-dark.css +0 -7
  50. package/themes/zhujian.css +0 -7
  51. package/themes/zhupi-dark.css +0 -7
  52. package/themes/zhupi.css +0 -7
  53. package/web/dist/assets/{TerminalPanel-CfxKLDW9.js → TerminalPanel-CslRhcS7.js} +2 -2
  54. package/web/dist/assets/index-C_2Fl6f6.js +690 -0
  55. package/web/dist/assets/index-D0BtO5dn.css +1 -0
  56. package/web/dist/index.html +2 -2
  57. package/web/dist/sw.js +1 -1
  58. package/web/dist/assets/index-BtcP6BDk.css +0 -1
  59. package/web/dist/assets/index-XVtCzcHR.js +0 -690
@@ -1,4 +1,4 @@
1
- import { killPidTree, lookupProcessName, lookupProcessCommandLine, snapshotListeningPorts, snapshotProcessParents, } from "./process-utils.js";
1
+ import { killPidTree, lookupProcessDetailsBatch, snapshotListeningPorts, snapshotProcessTree, } from "./process-utils.js";
2
2
  const BG_REFRESH_INTERVAL_MS = 30_000;
3
3
  /** bash 结束后等这么久再拍「后」快照——给后台服务绑定端口的时间。 */
4
4
  const BG_BIND_WAIT_MS = 1500;
@@ -20,11 +20,20 @@ export function staleLeftovers(entries, opts) {
20
20
  }
21
21
  /**
22
22
  * 基本不可能由 AI 启动的常驻桌面软件进程名(小写)。命中即跳过,避免面板被
23
- * 微信/QQ 等本地软件的动态监听端口污染。注意 Chrome 不进黑名单:AI 会用
23
+ * 微信/QQ/WPS/ima 等本地软件的动态监听端口污染。注意 Chrome 不进黑名单:AI 会用
24
24
  * Playwright 拉浏览器做模拟,它靠下方父链回溯判定(Playwright 起的 chrome
25
25
  * 能回溯到服务器进程,自己开的 chrome 父链是 explorer,分得开)。
26
26
  */
27
27
  export const NON_AGENT_PROCESS_NAMES = new Set([
28
+ // 办公与知识库(Issue #651:WPS、腾讯 ima.copilot 等)
29
+ "wps.exe",
30
+ "wpscenter.exe",
31
+ "ksoqing.exe",
32
+ "ksolaunch.exe",
33
+ "wpscloudsvr.exe",
34
+ "ima.copilot.exe",
35
+ "ima.exe",
36
+ // 即时通讯与社交
28
37
  "wechat.exe",
29
38
  "weixin.exe",
30
39
  "wechatappex.exe",
@@ -32,6 +41,7 @@ export const NON_AGENT_PROCESS_NAMES = new Set([
32
41
  "tim.exe",
33
42
  "telegram.exe",
34
43
  "dingtalk.exe",
44
+ // 系统外壳与基础设施
35
45
  "explorer.exe",
36
46
  "searchhost.exe",
37
47
  "searchapp.exe",
@@ -40,43 +50,176 @@ export const NON_AGENT_PROCESS_NAMES = new Set([
40
50
  "dwm.exe",
41
51
  "csrss.exe",
42
52
  "conhost.exe",
53
+ "sihost.exe",
54
+ "taskhostw.exe",
55
+ "services.exe",
56
+ "shellexperiencehost.exe",
57
+ "startmenuexperiencehost.exe",
58
+ ]);
59
+ /**
60
+ * 桌面外壳与系统服务进程名(小写)。
61
+ * 祖先回溯时如果撞上这些进程,说明该进程是由桌面 GUI、开始菜单或系统服务启动的,
62
+ * 绝不可能由当前 CLI / Node.js 进程在后台拉起。
63
+ */
64
+ export const SHELL_OR_SYSTEM_PROCESS_NAMES = new Set([
65
+ "explorer.exe",
66
+ "winlogon.exe",
67
+ "services.exe",
68
+ "dwm.exe",
69
+ "taskhostw.exe",
70
+ "sihost.exe",
71
+ "svchost.exe",
72
+ "shellexperiencehost.exe",
73
+ "startmenuexperiencehost.exe",
74
+ "system",
75
+ ]);
76
+ /**
77
+ * 典型的 AI / 开发者开发服务运行时进程名(小写)。
78
+ * 在发生中途断链(父进程已退出)时作为启发式白名单校验依据。
79
+ */
80
+ export const DEV_RUNTIME_PROCESS_NAMES = new Set([
81
+ "node.exe",
82
+ "node",
83
+ "python.exe",
84
+ "python",
85
+ "python3.exe",
86
+ "python3",
87
+ "deno.exe",
88
+ "deno",
89
+ "bun.exe",
90
+ "bun",
91
+ "ruby.exe",
92
+ "ruby",
93
+ "go.exe",
94
+ "go",
95
+ "java.exe",
96
+ "java",
97
+ "dotnet.exe",
98
+ "dotnet",
99
+ "php.exe",
100
+ "php",
101
+ "cargo.exe",
102
+ "cargo",
103
+ "uvicorn.exe",
104
+ "uvicorn",
105
+ "gunicorn",
106
+ "vite.exe",
107
+ "vite",
108
+ "flask.exe",
109
+ "flask",
43
110
  ]);
44
111
  /**
45
112
  * 判定 bash 后新出现的监听端口进程是否该记入后台任务列表(即「AI 启动的」)。
46
- * 判定规则(查不到就保守记录,宁多勿漏):
47
- * 1. 进程名命中黑名单(如 WeChat.exe,AI 不会去启动微信)→ 跳过;
48
- * 2. 进程树可查时沿父链向上回溯:
49
- * - 撞上服务器进程(serverPid,AI 的任何 bash/execFile 都从它 spawn)→ 记录;
50
- * - 撞上本次 diff 出的其他新 pid(bash 留下的中间层,如 concurrently/npm
51
- * 一类进程,它自己不监听端口所以没进 diff,但子进程监听)→ 记录;
52
- * - 完整回溯到系统根(pid 0/1)都未命中 → 桌面软件自启(如自己开的 Chrome,
53
- * 父链 explorer→…→0),跳过;
54
- * 3. 父链断链(父进程已退出/reparent,快照里查不到级联)→ 保守记录。
55
- * @param parents 全量 pid→ppid 映射,undefined = 查询失败(跳过父链判定,只留黑名单)。
56
- * @param newPids 本次 bash 前后 diff 出的全部新监听 pid。
113
+ *
114
+ * 判定规则(三重防护):
115
+ * 1. 【时序防线(CreationDate)】如果进程启动时间早于 bash 启动时刻(留 2s 容差),
116
+ * 说明该进程在 bash 执行前就已存在,100% 为外部已有应用(如提前开着的 WPS、ima、游戏),跳过;
117
+ * 2. 【进程名与黑名单】命中 NON_AGENT_PROCESS_NAMES(如 wps.exe、ima.copilot.exe、wechat.exe),跳过;
118
+ * 3. 【祖先链追溯】
119
+ * - 撞上服务器进程(serverPid)→ 记录(铁证);
120
+ * - 撞上桌面 Shell 或系统服务(explorer.exe / services.exe 等)→ 跳过;
121
+ * - 撞上本次 diff 出的其他新 pid(如 concurrently 等中间层)→ 记录并继续向上回溯;
122
+ * - 完整回溯到系统根(0/1)未命中 serverPid → 跳过;
123
+ * 4. 【断链安全底线】中途断链(父进程已退出,常见于 nohup 或 Windows launcher):
124
+ * - 具备明确开发特征(DEV_RUNTIME_PROCESS_NAMES 或命令行/路径包含工作区)才予收录;
125
+ * - 未知可执行文件或桌面安装目录应用(如 Program Files)坚决跳过,杜绝误杀用户正常程序。
57
126
  */
58
- export function shouldTrackBackgroundServer(pid, parents, newPids, serverPid, name) {
59
- if (name && NON_AGENT_PROCESS_NAMES.has(name.toLowerCase()))
127
+ export function shouldTrackBackgroundServer(pid, parents, newPids, serverPid, name, opts) {
128
+ const lowerName = name?.toLowerCase();
129
+ // 1. 命中黑名单 → 跳过
130
+ if (lowerName && NON_AGENT_PROCESS_NAMES.has(lowerName))
60
131
  return false;
61
- if (!parents)
62
- return true; // 进程树查不到 → 保守记录
132
+ // 2. 时序防护:早于 bash 开始时刻创建的进程绝不可能是本次命令拉起的新任务。
133
+ if (typeof opts?.startedBeforeMs === "number" &&
134
+ opts.startedBeforeMs > 0 &&
135
+ typeof opts.createdMs === "number" &&
136
+ opts.createdMs > 0) {
137
+ // 允许 2000ms 的时钟抖动/快照耗时容差
138
+ if (opts.createdMs < opts.startedBeforeMs - 2000) {
139
+ return false;
140
+ }
141
+ }
142
+ // 3. 命令行路径防范:如果可执行路径明显指向普通桌面安装目录(如 Program Files / AppData Local Programs)
143
+ // 且不是开发工具链运行时,跳过
144
+ if (opts?.commandLine) {
145
+ const lowerCmd = opts.commandLine.toLowerCase();
146
+ const isDevRuntime = lowerName ? DEV_RUNTIME_PROCESS_NAMES.has(lowerName) : false;
147
+ if (!isDevRuntime) {
148
+ const isDesktopPath = lowerCmd.includes("\\program files") ||
149
+ lowerCmd.includes("/program files") ||
150
+ lowerCmd.includes("\\appdata\\local\\programs\\") ||
151
+ lowerCmd.includes("/appdata/local/programs/");
152
+ if (isDesktopPath) {
153
+ return false;
154
+ }
155
+ }
156
+ }
157
+ // 4. 进程树查不到时:降级为保守记录(保持现有纯单测行为)
158
+ if (!parents) {
159
+ return true;
160
+ }
161
+ // 5. 向上回溯父链
63
162
  const seen = new Set();
64
163
  let cur = pid;
164
+ let brokenAt;
65
165
  while (cur !== undefined && !seen.has(cur)) {
66
166
  seen.add(cur);
67
167
  if (cur === serverPid)
68
168
  return true;
69
169
  if (cur !== pid && newPids.has(cur))
70
170
  return true;
71
- const next = parents.get(cur);
171
+ const parentEntry = parents.get(cur);
172
+ let next;
173
+ let parentName;
174
+ if (typeof parentEntry === "object" && parentEntry !== null) {
175
+ next = parentEntry.ppid;
176
+ parentName = parentEntry.name;
177
+ }
178
+ else if (typeof parentEntry === "number") {
179
+ next = parentEntry;
180
+ }
181
+ // 检查当前祖先节点是否命中桌面外壳或系统服务
182
+ if (parentName) {
183
+ const lowerParent = parentName.toLowerCase();
184
+ if (SHELL_OR_SYSTEM_PROCESS_NAMES.has(lowerParent) || NON_AGENT_PROCESS_NAMES.has(lowerParent)) {
185
+ return false;
186
+ }
187
+ }
72
188
  if (next === undefined) {
73
- // 到达系统根(0/1)→ 完整链,桌面软件;否则是断链 → 保守记录
74
- return cur <= 1 ? false : true;
189
+ // 到达系统根(0 或 1)→ 完整链,非 AI 启动
190
+ if (cur <= 1)
191
+ return false;
192
+ // 中途断链:父进程已退出
193
+ brokenAt = cur;
194
+ break;
195
+ }
196
+ if (next === cur) {
197
+ // 自引用根,视为完整链终点
198
+ return false;
75
199
  }
76
- if (next === cur)
77
- return false; // 自引用根,同样视为完整链终点
78
200
  cur = next;
79
201
  }
202
+ // 6. 断链处理(brokenAt !== undefined)
203
+ if (brokenAt !== undefined) {
204
+ // 如果未传 opts 且未传 name(保持现有纯断链单测的向后兼容)
205
+ if (!opts && !name) {
206
+ return true;
207
+ }
208
+ // 具备明确开发运行时特征(node, python 等)才予收录
209
+ if (lowerName && DEV_RUNTIME_PROCESS_NAMES.has(lowerName)) {
210
+ return true;
211
+ }
212
+ // 命令行包含当前工作区路径时收录
213
+ if (opts?.workspaceCwd && opts.commandLine) {
214
+ const normalizedCwd = opts.workspaceCwd.toLowerCase().replace(/\\/g, "/");
215
+ const normalizedCmd = opts.commandLine.toLowerCase().replace(/\\/g, "/");
216
+ if (normalizedCmd.includes(normalizedCwd)) {
217
+ return true;
218
+ }
219
+ }
220
+ // 默认断链不再盲目信任,防止误杀外部软件
221
+ return false;
222
+ }
80
223
  return false;
81
224
  }
82
225
  export class BgServerTracker {
@@ -90,6 +233,7 @@ export class BgServerTracker {
90
233
  * 读到 null 直接漏记,延迟解析的旧快照还会污染下一轮)。
91
234
  */
92
235
  listenBefore = null;
236
+ listenBeforeTime = 0;
93
237
  refreshTimer = null;
94
238
  constructor(opts) {
95
239
  this.opts = opts;
@@ -113,9 +257,12 @@ export class BgServerTracker {
113
257
  this.refreshTimer = null;
114
258
  }
115
259
  }
116
- /** tool_execution_start(bash):先记下「前」快照(快照在途时保留最早的一份)。 */
260
+ /** tool_execution_start(bash):先记下「前」快照(快照在途时保留最早的一份与启动时间)。 */
117
261
  snapshotBefore() {
118
- this.listenBefore ??= snapshotListeningPorts();
262
+ if (!this.listenBefore) {
263
+ this.listenBeforeTime = Date.now();
264
+ this.listenBefore = snapshotListeningPorts();
265
+ }
119
266
  }
120
267
  /** After a bash tool run, wait briefly for background servers to bind,
121
268
  * then diff the listening-port snapshot against the pre-run one and
@@ -124,7 +271,9 @@ export class BgServerTracker {
124
271
  // 读后清槽:await in-flight 快照(消除 fire-and-forget 的时序竞态),
125
272
  // 并发 bash 共用这份最早的基线,各自结束都能对得上。
126
273
  const beforePromise = this.listenBefore;
274
+ const beforeTime = this.listenBeforeTime;
127
275
  this.listenBefore = null;
276
+ this.listenBeforeTime = 0;
128
277
  if (!beforePromise)
129
278
  return;
130
279
  const before = await beforePromise;
@@ -138,30 +287,19 @@ export class BgServerTracker {
138
287
  }
139
288
  if (fresh.length === 0)
140
289
  return;
141
- // 剔除桌面软件误报(微信等)后,剩下的才是 AI 启动的后台服务。
142
- const keep = await this.filterAgentSpawned(fresh);
290
+ // 剔除桌面软件误报(微信/WPS/ima 等)后,剩下的才是 AI 启动的后台服务。
291
+ const keep = await this.filterAgentSpawned(fresh, beforeTime);
143
292
  let added = false;
144
- for (const { port, pid } of keep) {
293
+ for (const { port, pid, name, command } of keep) {
145
294
  if (this.servers.has(port))
146
295
  continue;
147
- this.servers.set(port, { pid, since: Date.now() });
148
- added = true;
149
- // Best-effort process name + full command line so the panel shows
150
- // something readable (name) AND what is actually running (command).
151
- void lookupProcessName(pid).then((name) => {
152
- const cur = this.servers.get(port);
153
- if (cur && cur.pid === pid && name) {
154
- cur.name = name;
155
- this.push();
156
- }
157
- });
158
- void lookupProcessCommandLine(pid).then((command) => {
159
- const cur = this.servers.get(port);
160
- if (cur && cur.pid === pid && command) {
161
- cur.command = command;
162
- this.push();
163
- }
296
+ this.servers.set(port, {
297
+ pid,
298
+ since: Date.now(),
299
+ ...(name ? { name } : {}),
300
+ ...(command ? { command } : {}),
164
301
  });
302
+ added = true;
165
303
  this.opts.emit({
166
304
  type: "notice",
167
305
  level: "info",
@@ -172,16 +310,30 @@ export class BgServerTracker {
172
310
  if (added)
173
311
  this.push();
174
312
  }
175
- /** 并行拉进程树与各进程名,用黑名单 + 父链回溯剔除桌面软件误报。 */
176
- async filterAgentSpawned(fresh) {
177
- const parents = await snapshotProcessParents();
178
- const names = await Promise.all(fresh.map((f) => lookupProcessName(f.pid)));
179
- const newPids = new Set(fresh.map((f) => f.pid));
313
+ /** 并行拉进程树与各进程详情,用时序防线 + 黑名单 + 父链回溯剔除桌面软件误报。 */
314
+ async filterAgentSpawned(fresh, beforeTime) {
315
+ const pids = [...new Set(fresh.map((f) => f.pid))];
316
+ const [tree, detailsMap] = await Promise.all([snapshotProcessTree(), lookupProcessDetailsBatch(pids)]);
317
+ const newPids = new Set(pids);
318
+ const cwd = this.opts.workspaceCwd?.();
180
319
  const out = [];
181
- for (let i = 0; i < fresh.length; i++) {
182
- const { port, pid } = fresh[i];
183
- if (shouldTrackBackgroundServer(pid, parents, newPids, process.pid, names[i])) {
184
- out.push({ port, pid });
320
+ for (const { port, pid } of fresh) {
321
+ const details = detailsMap.get(pid);
322
+ const name = details?.name;
323
+ const command = details?.commandLine;
324
+ const should = shouldTrackBackgroundServer(pid, tree, newPids, process.pid, name, {
325
+ commandLine: command,
326
+ createdMs: details?.createdMs,
327
+ startedBeforeMs: beforeTime > 0 ? beforeTime : undefined,
328
+ workspaceCwd: cwd,
329
+ });
330
+ if (should) {
331
+ out.push({
332
+ port,
333
+ pid,
334
+ ...(name ? { name } : {}),
335
+ ...(command ? { command } : {}),
336
+ });
185
337
  }
186
338
  }
187
339
  return out;
@@ -846,6 +846,7 @@ export class ClientStateStore {
846
846
  toolsWrap: stored?.toolsWrap ?? true,
847
847
  toolImagesEnabled: stored?.toolImagesEnabled ?? true,
848
848
  keepRecentMessages: normalizeKeepRecentMessages(stored?.keepRecentMessages),
849
+ reversePagination: stored?.reversePagination ?? false,
849
850
  showForkedParentSessions: stored?.showForkedParentSessions ?? false,
850
851
  retainFinishedConversations: stored?.retainFinishedConversations ?? false,
851
852
  openRecentSessionOnProjectSwitch: stored?.openRecentSessionOnProjectSwitch ?? true,
@@ -865,6 +866,7 @@ export class ClientStateStore {
865
866
  quickPhrases: stored?.quickPhrases ?? [],
866
867
  quickPhrasesEnabled: stored?.quickPhrasesEnabled ?? true,
867
868
  minimalNewChat: stored?.minimalNewChat ?? false,
869
+ preserveDraftAcrossConversations: stored?.preserveDraftAcrossConversations ?? false,
868
870
  reviewPrompt: stored?.reviewPrompt ?? "",
869
871
  reviewDisabledSkills: stored?.reviewDisabledSkills ?? [],
870
872
  disabledPlugins: stored?.disabledPlugins ?? [],
@@ -913,6 +915,7 @@ export class ClientStateStore {
913
915
  toolsWrap: settings.toolsWrap ?? cur.toolsWrap ?? true,
914
916
  toolImagesEnabled: settings.toolImagesEnabled ?? cur.toolImagesEnabled ?? true,
915
917
  keepRecentMessages: normalizeKeepRecentMessages(settings.keepRecentMessages ?? cur.keepRecentMessages ?? DEFAULT_KEEP_RECENT_MESSAGES),
918
+ reversePagination: settings.reversePagination ?? cur.reversePagination ?? false,
916
919
  showForkedParentSessions: settings.showForkedParentSessions ?? cur.showForkedParentSessions ?? false,
917
920
  retainFinishedConversations: settings.retainFinishedConversations ?? cur.retainFinishedConversations ?? false,
918
921
  openRecentSessionOnProjectSwitch: settings.openRecentSessionOnProjectSwitch ?? cur.openRecentSessionOnProjectSwitch ?? true,
@@ -941,6 +944,7 @@ export class ClientStateStore {
941
944
  quickPhrases: settings.quickPhrases ?? cur.quickPhrases ?? [],
942
945
  quickPhrasesEnabled: settings.quickPhrasesEnabled ?? cur.quickPhrasesEnabled ?? true,
943
946
  minimalNewChat: settings.minimalNewChat ?? cur.minimalNewChat ?? false,
947
+ preserveDraftAcrossConversations: settings.preserveDraftAcrossConversations ?? cur.preserveDraftAcrossConversations ?? false,
944
948
  defaultAgentPreset: settings.defaultAgentPreset ?? cur.defaultAgentPreset ?? "standard",
945
949
  defaultPermissionPreset: settings.defaultPermissionPreset ?? cur.defaultPermissionPreset ?? "workspace-write-never",
946
950
  };
@@ -1351,7 +1355,7 @@ export class ClientStateStore {
1351
1355
  /** 读取某客户端(标签页)上次使用的引擎(未设置返回 undefined)。 */
1352
1356
  getClientEngine(clientId) {
1353
1357
  const eng = this.load()[clientId]?.engine;
1354
- return eng === "dsh" || eng === "pi" || eng === "claude" ? eng : undefined;
1358
+ return eng === "dsh" || eng === "pi" || eng === "claude" || eng === "durable" ? eng : undefined;
1355
1359
  }
1356
1360
  /** 保存某客户端(标签页)当前使用的引擎。 */
1357
1361
  saveClientEngine(clientId, engine) {
@@ -1364,7 +1368,7 @@ export class ClientStateStore {
1364
1368
  /** 读取全局默认引擎(存在 __settings__ 下,新标签页及服务重启后默认跟随)。 */
1365
1369
  getDefaultEngine() {
1366
1370
  const eng = this.load()[ClientStateStore.GLOBAL_SETTINGS_KEY]?.defaultEngine;
1367
- return eng === "dsh" || eng === "pi" || eng === "claude" ? eng : undefined;
1371
+ return eng === "dsh" || eng === "pi" || eng === "claude" || eng === "durable" ? eng : undefined;
1368
1372
  }
1369
1373
  /** 保存全局默认引擎。 */
1370
1374
  saveDefaultEngine(engine) {
@@ -615,6 +615,8 @@ export function handleSettingsMessage(msg, cs) {
615
615
  quickPhrases: msg.quickPhrases,
616
616
  quickPhrasesEnabled: msg.quickPhrasesEnabled,
617
617
  minimalNewChat: msg.minimalNewChat,
618
+ preserveDraftAcrossConversations: msg
619
+ .preserveDraftAcrossConversations,
618
620
  quickPhrasesSeeded: msg.quickPhrasesSeeded,
619
621
  uiLayout: msg.uiLayout,
620
622
  });
@@ -48,9 +48,10 @@ import { checkAll as checkAllUpdates, collectTargets, resolveNpmRegistry } from
48
48
  import { collectInstalledEngineTargets } from "../engine-probe.js";
49
49
  import { previewKind } from "../text-sniff.js";
50
50
  import { removeQueuedByIndexOrText } from "../queue-utils.js";
51
+ import { ensureCredentialFilePermissions } from "../model-admin.js";
51
52
  import { launchOrigin, toServiceInfo } from "../launch-origin.js";
52
53
  import { DshRuntime, loadDeepSeekKey } from "./dsh-client.js";
53
- import { resolveProviderCredential, listCustomModelsFromConfig } from "../model-resolver.js";
54
+ import { resolveProviderCredential, listCustomModelsFromConfig, isModelProtocolSupportedByEngine, } from "../model-resolver.js";
54
55
  import { loadDshMarketData } from "./dsh-market-service.js";
55
56
  import { formatTextQuote, readTextQuote, messageTextWithQuotes } from "../text-quote.js";
56
57
  import { MarkerService } from "../marker-service.js";
@@ -159,6 +160,7 @@ const DEFAULT_SETTINGS = {
159
160
  quickPhrases: [],
160
161
  quickPhrasesEnabled: true,
161
162
  minimalNewChat: false,
163
+ preserveDraftAcrossConversations: false,
162
164
  promptTemplate: "",
163
165
  promptOverrides: {},
164
166
  };
@@ -257,6 +259,7 @@ export class DshClientSession {
257
259
  this.roots = stateStore.getWorkspaceRoots(clientId, cwd);
258
260
  this.dataDir = dataDir;
259
261
  this.agentDir = agentDir;
262
+ ensureCredentialFilePermissions(this.agentDir);
260
263
  this.sessionRoot = dshSessionRoot(dataDir);
261
264
  this.sandboxes = new SandboxManager(dataDir);
262
265
  try {
@@ -284,6 +287,7 @@ export class DshClientSession {
284
287
  isDisposed: () => this.disposed,
285
288
  pluginTasks: () => this.pluginBgTasksProvider?.() ?? [],
286
289
  cleanupMinutes: () => Number(this.settings.bgAutoCleanupMin ?? 0),
290
+ workspaceCwd: () => this.cwd,
287
291
  });
288
292
  this.markerSvc = new MarkerService({
289
293
  clientId,
@@ -352,6 +356,7 @@ export class DshClientSession {
352
356
  quickPhrases: savedSettings.quickPhrases ?? [],
353
357
  quickPhrasesEnabled: savedSettings.quickPhrasesEnabled ?? true,
354
358
  minimalNewChat: savedSettings.minimalNewChat ?? false,
359
+ preserveDraftAcrossConversations: savedSettings.preserveDraftAcrossConversations ?? false,
355
360
  promptTemplate: savedSettings.promptTemplate ?? "",
356
361
  promptOverrides: savedSettings.promptOverrides ?? {},
357
362
  defaultAgentPreset: savedSettings.defaultAgentPreset ?? PRESET_DEFAULT_ID,
@@ -3159,13 +3164,18 @@ export class DshClientSession {
3159
3164
  // 审查会话不进搜索。
3160
3165
  if (sessionId.startsWith("review-"))
3161
3166
  continue;
3162
- if (all.includes(q) ||
3163
- sessionId.toLowerCase().includes(q) ||
3164
- firstUserText(events, this.getLang()).toLowerCase().includes(q)) {
3167
+ const firstMsg = firstUserText(events, this.getLang());
3168
+ if (all.includes(q) || sessionId.toLowerCase().includes(q) || firstMsg.toLowerCase().includes(q)) {
3169
+ const storedTitle = this.stateStore?.getSessionTitle(this.cwd, file) ?? this.stateStore?.getSessionTitle(this.cwd, sessionId);
3170
+ const explicitTitle = storedTitle ??
3171
+ sessionLogTitle(events) ??
3172
+ [...this.convs.values()].find((c) => c.sessionId === sessionId && !DshClientSession.isDefaultTitle(c.title))?.title;
3173
+ const displayName = this.resolveSessionDisplayName(sessionId, explicitTitle, firstMsg);
3165
3174
  results.push({
3166
3175
  path: file,
3167
- name: sessionId,
3168
- firstMessage: firstUserText(events, this.getLang()),
3176
+ name: explicitTitle ?? sessionId,
3177
+ displayName,
3178
+ firstMessage: firstMsg,
3169
3179
  messageCount: events.filter((e) => (e.type === "user/message" && !isDshInternalUserMessage(e.data)) ||
3170
3180
  e.type === "assistant/message" ||
3171
3181
  e.type === "tool/result").length,
@@ -3308,9 +3318,9 @@ export class DshClientSession {
3308
3318
  vision,
3309
3319
  });
3310
3320
  }
3311
- // 3. 用户在 models.json 中配置的第三方自定义端点模型
3321
+ // 3. 用户在 models.json 中配置的第三方自定义端点模型(针对性过滤 DSH 不支持的协议,如 anthropic-messages)
3312
3322
  try {
3313
- const custom = listCustomModelsFromConfig(this.agentDir);
3323
+ const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("dsh", entry));
3314
3324
  for (const c of custom) {
3315
3325
  const canonicalId = `${c.providerId}/${c.modelId}`;
3316
3326
  if (seen.has(canonicalId))
@@ -3364,7 +3374,7 @@ export class DshClientSession {
3364
3374
  }
3365
3375
  else {
3366
3376
  try {
3367
- const customList = listCustomModelsFromConfig(this.agentDir);
3377
+ const customList = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("dsh", entry));
3368
3378
  const hit = customList.find((c) => `${c.providerId}/${c.modelId}` === normId || c.modelId === normId || c.modelId === bareModelId);
3369
3379
  if (hit) {
3370
3380
  meta = {
@@ -3603,6 +3613,7 @@ export class DshClientSession {
3603
3613
  quickPhrases: [...this.settings.quickPhrases],
3604
3614
  quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
3605
3615
  minimalNewChat: this.settings.minimalNewChat,
3616
+ preserveDraftAcrossConversations: this.settings.preserveDraftAcrossConversations ?? false,
3606
3617
  quickPhrasesSeeded: this.stateStore.getQuickPhrasesSeeded(),
3607
3618
  };
3608
3619
  this.emit({ type: "settings_state", settings });
@@ -3675,6 +3686,8 @@ export class DshClientSession {
3675
3686
  this.settings.quickPhrasesEnabled = partial.quickPhrasesEnabled;
3676
3687
  if (partial.minimalNewChat !== undefined)
3677
3688
  this.settings.minimalNewChat = partial.minimalNewChat;
3689
+ if (partial.preserveDraftAcrossConversations !== undefined)
3690
+ this.settings.preserveDraftAcrossConversations = partial.preserveDraftAcrossConversations;
3678
3691
  const prevMarkerGuidance = this.markerSvc.buildGuidance();
3679
3692
  this.markerSvc.setAll({
3680
3693
  markersEnabled: partial.markersEnabled,
@@ -3714,6 +3727,7 @@ export class DshClientSession {
3714
3727
  quickPhrases: this.settings.quickPhrases,
3715
3728
  quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
3716
3729
  minimalNewChat: this.settings.minimalNewChat,
3730
+ preserveDraftAcrossConversations: this.settings.preserveDraftAcrossConversations,
3717
3731
  defaultAgentPreset: this.settings.defaultAgentPreset,
3718
3732
  promptTemplate: this.settings.promptTemplate ?? "",
3719
3733
  promptOverrides: this.settings.promptOverrides ?? {},
@@ -4822,7 +4836,7 @@ export class DshClientSession {
4822
4836
  return true;
4823
4837
  }
4824
4838
  try {
4825
- const custom = listCustomModelsFromConfig(this.agentDir);
4839
+ const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("dsh", entry));
4826
4840
  if (custom.length > 0) {
4827
4841
  for (const c of custom) {
4828
4842
  if (resolveProviderCredential(this.agentDir, c.providerId).apiKey)