pi-web-ui 0.104.4 → 0.105.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 (52) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -1
  3. package/README.zh-CN.md +2 -2
  4. package/bin/pi-web-ui.mjs +9 -3
  5. package/dist/server/agent-service-daemon.js +7 -7
  6. package/dist/server/agent-service.js +497 -109
  7. package/dist/server/approval-default-rules.js +15 -0
  8. package/dist/server/client-state.js +29 -0
  9. package/dist/server/dispatch-domain-handlers.js +35 -7
  10. package/dist/server/dsh/dsh-agent-service.js +88 -33
  11. package/dist/server/dsh/dsh-serialize.js +16 -1
  12. package/dist/server/ensure-bash.js +7 -2
  13. package/dist/server/file-transfer-routes.js +114 -1
  14. package/dist/server/index.js +347 -68
  15. package/dist/server/load-tools-tool.js +2 -1
  16. package/dist/server/locales.js +5 -0
  17. package/dist/server/markers/marker.js +28 -0
  18. package/dist/server/mcp-bridge.js +20 -6
  19. package/dist/server/pkg-info.js +69 -0
  20. package/dist/server/plugin-facilities.js +18 -9
  21. package/dist/server/plugin-manifest-validate.js +3 -0
  22. package/dist/server/plugin-updater.js +11 -5
  23. package/dist/server/plugins.js +3 -12
  24. package/dist/server/present-files-tool.js +47 -1
  25. package/dist/server/preset-fields.js +14 -0
  26. package/dist/server/preset-share.js +5 -12
  27. package/dist/server/prompt-composer.js +1 -1
  28. package/dist/server/remote-ssh-service.js +158 -5
  29. package/dist/server/serialize.js +15 -4
  30. package/dist/server/session-parser.js +138 -2
  31. package/dist/server/settings-service.js +19 -0
  32. package/dist/server/terminals.js +7 -1
  33. package/dist/server/text-quote.js +64 -2
  34. package/dist/server/tool-manager.js +10 -0
  35. package/dist/server/tool-prompts.js +1 -0
  36. package/dist/server/update-check.js +98 -24
  37. package/dist/server/workspace-snapshot.js +251 -13
  38. package/dist/server/worktree-service.js +262 -0
  39. package/dist/server/worktree-tool.js +173 -0
  40. package/package.json +3 -1
  41. package/plugin-sdk/index.d.ts +14 -1
  42. package/themes/zhujian-dark.css +16 -4
  43. package/themes/zhujian.css +16 -4
  44. package/themes/zhupi-dark.css +16 -4
  45. package/themes/zhupi.css +16 -4
  46. package/web/dist/assets/{TerminalPanel-B7x99tkg.js → TerminalPanel-B9exeXrl.js} +1 -1
  47. package/web/dist/assets/index-BQC6lADz.css +1 -0
  48. package/web/dist/assets/index-D79IKG33.js +690 -0
  49. package/web/dist/index.html +21 -21
  50. package/web/dist/sw.js +1 -1
  51. package/web/dist/assets/index-DOrLcjLY.js +0 -680
  52. package/web/dist/assets/index-_H2BS7OX.css +0 -1
@@ -65,6 +65,21 @@ export const DEFAULT_APPROVAL_RULES = [
65
65
  categoryId: "bash.git-destructive",
66
66
  builtin: true,
67
67
  },
68
+ {
69
+ id: "builtin.bash.git-worktree",
70
+ enabled: true,
71
+ tools: ["bash"],
72
+ field: "command",
73
+ match: "regex",
74
+ value: "\\bgit(?:\\.exe)?(?:\\s+(?:-[cC]\\s+\\S+|--[a-zA-Z-]+=\\S+))*\\s+worktree\\s+(add|remove|prune)\\b",
75
+ action: "ask",
76
+ label: "Git 工作树操作 (git worktree)",
77
+ labelEn: "Git worktree operation (git worktree)",
78
+ reason: "检测到通过 Bash 执行 git worktree 操作;建议使用专门的 worktree 工具以确保界面感知与工作区同步",
79
+ reasonEn: "Detected git worktree via Bash; prefer using the dedicated worktree tool to keep the UI synchronized",
80
+ categoryId: "bash.git-worktree",
81
+ builtin: true,
82
+ },
68
83
  {
69
84
  id: "builtin.bash.chmod",
70
85
  enabled: true,
@@ -838,6 +838,8 @@ export class ClientStateStore {
838
838
  toolsWrap: stored?.toolsWrap ?? true,
839
839
  toolImagesEnabled: stored?.toolImagesEnabled ?? true,
840
840
  keepRecentMessages: normalizeKeepRecentMessages(stored?.keepRecentMessages),
841
+ showForkedParentSessions: stored?.showForkedParentSessions ?? false,
842
+ retainFinishedConversations: stored?.retainFinishedConversations ?? false,
841
843
  skillsFullText: normalizeSkillList(stored?.skillsFullText),
842
844
  visionBridgeEnabled: stored?.visionBridgeEnabled ?? true,
843
845
  visionBridgeModel: stored?.visionBridgeModel ?? null,
@@ -901,6 +903,8 @@ export class ClientStateStore {
901
903
  toolsWrap: settings.toolsWrap ?? cur.toolsWrap ?? true,
902
904
  toolImagesEnabled: settings.toolImagesEnabled ?? cur.toolImagesEnabled ?? true,
903
905
  keepRecentMessages: normalizeKeepRecentMessages(settings.keepRecentMessages ?? cur.keepRecentMessages ?? DEFAULT_KEEP_RECENT_MESSAGES),
906
+ showForkedParentSessions: settings.showForkedParentSessions ?? cur.showForkedParentSessions ?? false,
907
+ retainFinishedConversations: settings.retainFinishedConversations ?? cur.retainFinishedConversations ?? false,
904
908
  skillsFullText: normalizeSkillList(settings.skillsFullText ?? cur.skillsFullText),
905
909
  visionBridgeEnabled: settings.visionBridgeEnabled ?? cur.visionBridgeEnabled ?? true,
906
910
  // 按键存在性合并:null 是合法值(清除语义),`null ?? cur` 会把旧值
@@ -1269,4 +1273,29 @@ export class ClientStateStore {
1269
1273
  };
1270
1274
  this.save();
1271
1275
  }
1276
+ /** 读取某客户端(标签页)上次使用的引擎(未设置返回 undefined)。 */
1277
+ getClientEngine(clientId) {
1278
+ const eng = this.load()[clientId]?.engine;
1279
+ return eng === "dsh" || eng === "pi" ? eng : undefined;
1280
+ }
1281
+ /** 保存某客户端(标签页)当前使用的引擎。 */
1282
+ saveClientEngine(clientId, engine) {
1283
+ const all = this.load();
1284
+ const state = (all[clientId] ??= { projects: [] });
1285
+ state.engine = engine;
1286
+ this.touchClient(all, clientId);
1287
+ this.save();
1288
+ }
1289
+ /** 读取全局默认引擎(存在 __settings__ 下,新标签页及服务重启后默认跟随)。 */
1290
+ getDefaultEngine() {
1291
+ const eng = this.load()[ClientStateStore.GLOBAL_SETTINGS_KEY]?.defaultEngine;
1292
+ return eng === "dsh" || eng === "pi" ? eng : undefined;
1293
+ }
1294
+ /** 保存全局默认引擎。 */
1295
+ saveDefaultEngine(engine) {
1296
+ const all = this.load();
1297
+ const state = (all[ClientStateStore.GLOBAL_SETTINGS_KEY] ??= { projects: [] });
1298
+ state.defaultEngine = engine;
1299
+ this.save();
1300
+ }
1272
1301
  }
@@ -42,17 +42,38 @@ export function handleFileMessage(msg, cs) {
42
42
  void cs.makeDir(msg.path, msg.setAsCwd === true);
43
43
  return true;
44
44
  case "set_cwd":
45
- void cs.setCwd(msg.path);
45
+ void (async () => {
46
+ try {
47
+ await cs.setCwd(msg.path);
48
+ }
49
+ catch (err) {
50
+ cs.emitNotice("error", `切换工作目录失败:${err.message}`, `Failed to switch workspace: ${err.message}`);
51
+ }
52
+ })();
46
53
  return true;
47
54
  case "set_workspace_roots":
48
- void cs.setWorkspaceRoots(msg.roots);
55
+ void (async () => {
56
+ try {
57
+ await cs.setWorkspaceRoots(msg.roots);
58
+ }
59
+ catch (err) {
60
+ cs.emitNotice("error", `设置额外工作区根失败:${err.message}`, `Failed to set workspace roots: ${err.message}`);
61
+ }
62
+ })();
49
63
  return true;
50
64
  case "create_sandbox":
51
- void cs.createSandbox?.({
52
- name: msg.name,
53
- sourcePath: msg.sourcePath,
54
- ephemeral: msg.ephemeral,
55
- });
65
+ void (async () => {
66
+ try {
67
+ await cs.createSandbox?.({
68
+ name: msg.name,
69
+ sourcePath: msg.sourcePath,
70
+ ephemeral: msg.ephemeral,
71
+ });
72
+ }
73
+ catch (err) {
74
+ cs.emitNotice("error", `创建沙盒失败:${err.message}`, `Failed to create sandbox: ${err.message}`);
75
+ }
76
+ })();
56
77
  return true;
57
78
  case "reset_sandbox":
58
79
  void cs.resetSandbox?.(msg.path);
@@ -105,6 +126,12 @@ export function handleScmMessage(msg, cs, send) {
105
126
  });
106
127
  }
107
128
  return true;
129
+ case "switch_worktree":
130
+ void cs.switchWorktree?.(msg.path);
131
+ return true;
132
+ case "remove_worktree":
133
+ void cs.removeWorktree?.(msg.path, msg.force);
134
+ return true;
108
135
  default:
109
136
  return false;
110
137
  }
@@ -555,6 +582,7 @@ export function handleSettingsMessage(msg, cs) {
555
582
  toolsWrap: msg.toolsWrap,
556
583
  toolImagesEnabled: msg.toolImagesEnabled,
557
584
  keepRecentMessages: msg.keepRecentMessages,
585
+ showForkedParentSessions: msg.showForkedParentSessions,
558
586
  devNoCache: msg.devNoCache,
559
587
  autoReload: msg.autoReload,
560
588
  skillsFullText: msg.skillsFullText,
@@ -48,11 +48,13 @@ import { removeQueuedByIndexOrText } from "../queue-utils.js";
48
48
  import { launchOrigin, toServiceInfo } from "../launch-origin.js";
49
49
  import { DshRuntime, loadDeepSeekKey } from "./dsh-client.js";
50
50
  import { formatTextQuote, readTextQuote, messageTextWithQuotes } from "../text-quote.js";
51
- import { DshStreamAccumulator, assistantMessageEventToUiMessage, toolResultEventToUiMessage, userMessageEventToUiMessage, } from "./dsh-serialize.js";
51
+ import { MarkerService } from "../marker-service.js";
52
+ import { DshStreamAccumulator, assistantMessageEventToUiMessage, extractDshAssistantRawText, toolResultEventToUiMessage, userMessageEventToUiMessage, } from "./dsh-serialize.js";
52
53
  import { firstUserText, findSessionFilesForCwd, readSessionLog, replayEventsToMessages, sessionLogPermission, sessionLogPreset, } from "./dsh-sessions.js";
53
54
  import { generatePresetClones, PRESET_DEFAULT_ID } from "./preset-clones.js";
54
55
  import { dshContextUsage, lastUsageFromEvents, normalizeDshUsage } from "./dsh-usage.js";
55
56
  import { exportPresetVia, importPresetFromUrlVia, importPresetVia, packageVersion, pushPresetCatalogVia, sharePresetVia, } from "../preset-share.js";
57
+ import { getAppVersion } from "../pkg-info.js";
56
58
  import { getMaxOpenConversations } from "../agent-formatters.js";
57
59
  const SNAPSHOT_INTERVAL_MS = 60;
58
60
  /** 用户主目录(wire 格式):进程内不变,模块加载时求值一次(右栏 🏠)。 */
@@ -141,6 +143,8 @@ const DEFAULT_SETTINGS = {
141
143
  toolsWrap: true,
142
144
  toolImagesEnabled: true,
143
145
  keepRecentMessages: DEFAULT_KEEP_RECENT_MESSAGES,
146
+ showForkedParentSessions: false,
147
+ retainFinishedConversations: false,
144
148
  disabledPlugins: [],
145
149
  uiLayout: {},
146
150
  reviewPrompt: "",
@@ -215,6 +219,7 @@ export class DshClientSession {
215
219
  files;
216
220
  bg;
217
221
  sandboxes;
222
+ markerSvc;
218
223
  /** 插件扩展点(index.ts 注入)。 */
219
224
  onToolEvent;
220
225
  pluginToolsProvider;
@@ -261,6 +266,23 @@ export class DshClientSession {
261
266
  pluginTasks: () => this.pluginBgTasksProvider?.() ?? [],
262
267
  cleanupMinutes: () => Number(this.settings.bgAutoCleanupMin ?? 0),
263
268
  });
269
+ this.markerSvc = new MarkerService({
270
+ clientId,
271
+ stateStore,
272
+ emit: (msg) => this.emit(msg),
273
+ isDisposed: () => this.disposed,
274
+ getActiveConversationId: () => this.activeId,
275
+ getSessionManager: () => undefined,
276
+ renameConversation: (convId, title) => {
277
+ void this.renameConversation(convId, title);
278
+ },
279
+ refreshMarkers: () => this.flushSnapshot(),
280
+ onActionsChange: (convId) => {
281
+ if (convId === this.activeId)
282
+ this.flushSnapshot();
283
+ },
284
+ lang: () => this.getLang(),
285
+ });
264
286
  }
265
287
  static create(clientId, cwd, stateStore, dataDir, agentDir) {
266
288
  const cs = new DshClientSession(clientId, cwd, stateStore, dataDir, agentDir ?? join(homedir(), ".pi", "agent"));
@@ -297,6 +319,8 @@ export class DshClientSession {
297
319
  toolsWrap: savedSettings.toolsWrap,
298
320
  toolImagesEnabled: savedSettings.toolImagesEnabled ?? true,
299
321
  keepRecentMessages: normalizeKeepRecentMessages(savedSettings.keepRecentMessages),
322
+ showForkedParentSessions: savedSettings.showForkedParentSessions ?? false,
323
+ retainFinishedConversations: savedSettings.retainFinishedConversations ?? false,
300
324
  disabledPlugins: savedSettings.disabledPlugins ?? [],
301
325
  uiLayout: normalizeUiLayout(savedSettings.uiLayout),
302
326
  reviewPrompt: savedSettings.reviewPrompt,
@@ -539,7 +563,7 @@ export class DshClientSession {
539
563
  agentDir: this.agentDir,
540
564
  env: {
541
565
  ...(presetPatch ? { PI_WEB_DSH_PRESET_PATCH: presetPatch } : {}),
542
- PI_WEB_DSH_CUSTOM_PROMPT: this.settings.customSystemPrompt.trim(),
566
+ ...this.buildPersonaEnv(),
543
567
  },
544
568
  });
545
569
  }
@@ -949,6 +973,10 @@ export class DshClientSession {
949
973
  conv.streaming = null;
950
974
  this.appendMessage(conv, msg);
951
975
  }
976
+ const rawText = extractDshAssistantRawText(ev.data);
977
+ if (rawText && rawText.includes("[[")) {
978
+ void this.markerSvc.handleAssistantText(conv.id, rawText);
979
+ }
952
980
  // 新版运行时的 usage 挂在这条持久事件上(老运行时没有 → undefined 保持原统计)。
953
981
  this.applyUsage(conv, ev.data.usage);
954
982
  break;
@@ -1053,7 +1081,10 @@ export class DshClientSession {
1053
1081
  break;
1054
1082
  }
1055
1083
  // 事件驱动快照(60ms 节流;边界事件立即)。
1056
- if (ev.type === "turn/end" || ev.type === "tool/result" || ev.type === "assistant/message") {
1084
+ if (ev.type === "turn/end" ||
1085
+ ev.type === "tool/result" ||
1086
+ ev.type === "assistant/message" ||
1087
+ ev.type === "agent/inbox/spliced") {
1057
1088
  this.flushSnapshot();
1058
1089
  }
1059
1090
  else {
@@ -1276,7 +1307,7 @@ export class DshClientSession {
1276
1307
  permission: conv.permissionPreset ?? null,
1277
1308
  queue: { steering: conv.queue.steering, followUp: conv.queue.followUp },
1278
1309
  pendingQuestion: this.pendingQuestionForSnapshot(),
1279
- actionSuggestions: null,
1310
+ actionSuggestions: this.markerSvc.getActionSuggestions(this.activeId) ?? null,
1280
1311
  tools: [],
1281
1312
  version: ++this.version,
1282
1313
  piConfigured: this.isDshConfigured(),
@@ -1426,6 +1457,17 @@ export class DshClientSession {
1426
1457
  ...(elsewhere.length > 0 ? { elsewhere } : {}),
1427
1458
  });
1428
1459
  }
1460
+ shouldRetainDshConversation(conv) {
1461
+ if (conv.isStreaming)
1462
+ return true;
1463
+ if (conv.terminals.countBlockingLive() > 0)
1464
+ return true;
1465
+ if (conv.promptedSinceActive)
1466
+ return true;
1467
+ if (this.settings?.retainFinishedConversations && (conv.messages.length > 0 || conv.listed))
1468
+ return true;
1469
+ return false;
1470
+ }
1429
1471
  /** 语义同 pi 引擎的 newChat:true = 当前活动对话是可接收首条的空白新对话
1430
1472
  * (/new <prompt> 靠它决定要不要把首条提示发出去)。preset = 新会话预设
1431
1473
  * (复用空白会话时等价一次空白切换)。 */
@@ -1467,7 +1509,7 @@ export class DshClientSession {
1467
1509
  }
1468
1510
  // 旧对话保留(listed 生命周期简化:不主动移除)。
1469
1511
  const prevModel = this.model;
1470
- active.listed = active.isStreaming || active.terminals.countBlockingLive() > 0 || active.promptedSinceActive;
1512
+ active.listed = this.shouldRetainDshConversation(active);
1471
1513
  const conv = this.addConversation(`chat-${randomUUID().slice(0, 12)}`, this.cwd, false, preset);
1472
1514
  this.activeId = conv.id;
1473
1515
  this.model = prevModel;
@@ -1484,7 +1526,7 @@ export class DshClientSession {
1484
1526
  return;
1485
1527
  const prev = this.conv;
1486
1528
  // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
1487
- prev.listed = prev.isStreaming || prev.terminals.countBlockingLive() > 0 || prev.promptedSinceActive;
1529
+ prev.listed = this.shouldRetainDshConversation(prev);
1488
1530
  this.activeId = id;
1489
1531
  // 后台列表可能属于另一项目 → 切会话同时切工作区(与 pi 一致:文件树/
1490
1532
  // 会话历史/最近项目跟着走)。DSH 单 runtime 换 cwd → 异步重启。
@@ -1548,6 +1590,7 @@ export class DshClientSession {
1548
1590
  }
1549
1591
  }
1550
1592
  let conv = this.conv;
1593
+ this.markerSvc.clearActions(conv.id);
1551
1594
  // issue #145:同文件守卫 —— 别处正在跑同一 sessionId 时拒绝发送(不造第二个 writer)。
1552
1595
  const fileOwner = this.findSessionOwnerById?.(conv.sessionId);
1553
1596
  if (fileOwner && fileOwner.isStreaming) {
@@ -1714,15 +1757,16 @@ export class DshClientSession {
1714
1757
  },
1715
1758
  };
1716
1759
  this.appendMessage(conv, optimistic);
1717
- this.flushSnapshot();
1718
1760
  if (conv.isStreaming) {
1719
1761
  // DSH 无 mid-run steering:isStreaming 时入队(followUp),
1720
- // 运行时 inbox 在 run 结束后消费。
1762
+ // 运行时 inbox 在 run 结束后消费。入队后立即 flushSnapshot 让排队气泡上屏。
1721
1763
  conv.queue.followUp.push(text);
1764
+ this.flushSnapshot();
1722
1765
  await this.runtime.prompt(conv.sessionId, blocks);
1723
1766
  conv.queue.followUp = conv.queue.followUp.filter((t) => t !== text);
1724
1767
  }
1725
1768
  else {
1769
+ this.flushSnapshot();
1726
1770
  await this.runtime.prompt(conv.sessionId, blocks);
1727
1771
  }
1728
1772
  // 首轮用户发言送达 → 预设锁定(官方语义;回放会话建时已锁)。
@@ -2288,7 +2332,7 @@ export class DshClientSession {
2288
2332
  }
2289
2333
  const prev = this.conv;
2290
2334
  // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
2291
- prev.listed = prev.isStreaming || prev.terminals.countBlockingLive() > 0 || prev.promptedSinceActive;
2335
+ prev.listed = this.shouldRetainDshConversation(prev);
2292
2336
  const conv = this.addConversation(sessionId, this.cwd, true);
2293
2337
  conv.fromDisk = true; // 磁盘回放 → prompt 时 fork
2294
2338
  this.activeId = conv.id;
@@ -2914,6 +2958,8 @@ export class DshClientSession {
2914
2958
  toolsWrap: this.settings.toolsWrap,
2915
2959
  toolImagesEnabled: this.settings.toolImagesEnabled,
2916
2960
  keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
2961
+ showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
2962
+ retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
2917
2963
  // DSH 无 skill 全文注入概念,给空保协议完整。
2918
2964
  skillsFullText: [],
2919
2965
  visionBridgeEnabled: false,
@@ -2946,9 +2992,9 @@ export class DshClientSession {
2946
2992
  reviewSkills: [],
2947
2993
  extensions: [],
2948
2994
  presets: this.stateStore.getPresets(this.clientId).map(settingsPresetToUi),
2949
- markersEnabled: true,
2950
- disabledMarkers: [],
2951
- markers: [],
2995
+ markersEnabled: this.markerSvc.current.markersEnabled,
2996
+ disabledMarkers: [...this.markerSvc.current.disabledMarkers],
2997
+ markers: this.markerSvc.listForUi(),
2952
2998
  subagentTemplates: [],
2953
2999
  subagentDefaultTemplates: [],
2954
3000
  subagentDefaultModel: null,
@@ -3004,6 +3050,10 @@ export class DshClientSession {
3004
3050
  this.settings.toolImagesEnabled = partial.toolImagesEnabled;
3005
3051
  if (partial.keepRecentMessages !== undefined)
3006
3052
  this.settings.keepRecentMessages = normalizeKeepRecentMessages(partial.keepRecentMessages);
3053
+ if (partial.showForkedParentSessions !== undefined)
3054
+ this.settings.showForkedParentSessions = Boolean(partial.showForkedParentSessions);
3055
+ if (partial.retainFinishedConversations !== undefined)
3056
+ this.settings.retainFinishedConversations = Boolean(partial.retainFinishedConversations);
3007
3057
  if (partial.disabledPlugins !== undefined)
3008
3058
  this.settings.disabledPlugins = partial.disabledPlugins;
3009
3059
  if (partial.uiLayout !== undefined)
@@ -3019,6 +3069,12 @@ export class DshClientSession {
3019
3069
  }
3020
3070
  if (partial.quickPhrasesEnabled !== undefined)
3021
3071
  this.settings.quickPhrasesEnabled = partial.quickPhrasesEnabled;
3072
+ const prevMarkerGuidance = this.markerSvc.buildGuidance();
3073
+ this.markerSvc.setAll({
3074
+ markersEnabled: partial.markersEnabled,
3075
+ disabledMarkers: partial.disabledMarkers,
3076
+ });
3077
+ const markerGuidanceChanged = this.markerSvc.buildGuidance() !== prevMarkerGuidance;
3022
3078
  // 持久化(跨重连存活)。
3023
3079
  this.stateStore.saveSettings(this.clientId, {
3024
3080
  promptMode: this.settings.promptMode,
@@ -3043,6 +3099,8 @@ export class DshClientSession {
3043
3099
  toolsWrap: this.settings.toolsWrap,
3044
3100
  toolImagesEnabled: this.settings.toolImagesEnabled,
3045
3101
  keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
3102
+ showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
3103
+ retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
3046
3104
  disabledPlugins: this.settings.disabledPlugins,
3047
3105
  uiLayout: normalizeUiLayout(this.settings.uiLayout),
3048
3106
  reviewPrompt: this.settings.reviewPrompt,
@@ -3052,9 +3110,9 @@ export class DshClientSession {
3052
3110
  promptTemplate: this.settings.promptTemplate ?? "",
3053
3111
  promptOverrides: this.settings.promptOverrides ?? {},
3054
3112
  });
3055
- // 仅系统提示词变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
3113
+ // 仅系统提示词或内联标记指引变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
3056
3114
  // 其他设置(开关/隐藏插件等)只存不回写运行时。
3057
- const personaChanged = partial.promptMode !== undefined || partial.customSystemPrompt !== undefined;
3115
+ const personaChanged = partial.promptMode !== undefined || partial.customSystemPrompt !== undefined || markerGuidanceChanged;
3058
3116
  if (personaChanged)
3059
3117
  await this.applyPersona();
3060
3118
  // 技能启停(#18):禁用集变化 → 同步运行时(晚 pre-step 钩子过滤目录)并刷新技能列表。
@@ -3065,17 +3123,22 @@ export class DshClientSession {
3065
3123
  this.pushSettings();
3066
3124
  this.flushSnapshot();
3067
3125
  }
3068
- applyPersona() {
3126
+ buildPersonaEnv() {
3069
3127
  const custom = this.settings.customSystemPrompt.trim();
3128
+ const markerGuidance = this.markerSvc.buildGuidance().trim();
3129
+ const effectiveCustom = [custom, markerGuidance].filter(Boolean).join("\n\n");
3070
3130
  const persona = this.settings.promptMode === "replace" && custom
3071
- ? custom
3072
- : this.settings.promptMode === "append" && custom
3073
- ? `\n\n${custom}`
3131
+ ? effectiveCustom
3132
+ : effectiveCustom
3133
+ ? `\n\n${effectiveCustom}`
3074
3134
  : "";
3135
+ return { DSH_PERSONA: persona, PI_WEB_DSH_CUSTOM_PROMPT: effectiveCustom };
3136
+ }
3137
+ applyPersona() {
3075
3138
  // 自定义提示词双通道:DSH_PERSONA(host 部署人设;预设 persona 会 shadow 它,
3076
3139
  // minimal 更全压住)+ PI_WEB_DSH_CUSTOM_PROMPT(独立 host section,随
3077
3140
  // standard/ptc/cordis 下发;minimal 下被 complete 压住,官方语义)。
3078
- this.runtime.env = { ...this.runtime.env, DSH_PERSONA: persona, PI_WEB_DSH_CUSTOM_PROMPT: custom };
3141
+ this.runtime.env = { ...this.runtime.env, ...this.buildPersonaEnv() };
3079
3142
  if (this.runtime.alive) {
3080
3143
  return this.runtime.restart(this.model).catch(() => {
3081
3144
  /* keep old runtime */
@@ -3433,6 +3496,8 @@ export class DshClientSession {
3433
3496
  toolsWrap: this.settings.toolsWrap,
3434
3497
  toolImagesEnabled: this.settings.toolImagesEnabled,
3435
3498
  keepRecentMessages: normalizeKeepRecentMessages(this.settings.keepRecentMessages),
3499
+ showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
3500
+ retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
3436
3501
  disabledPlugins: this.settings.disabledPlugins,
3437
3502
  uiLayout: normalizeUiLayout(this.settings.uiLayout),
3438
3503
  reviewPrompt: this.settings.reviewPrompt,
@@ -4030,13 +4095,7 @@ export class DshClientSession {
4030
4095
  // 自更新
4031
4096
  // -----------------------------------------------------------------------
4032
4097
  static currentAppVersion() {
4033
- try {
4034
- const pkg = JSON.parse(readFileSync(join(dirname(new URL(import.meta.url).pathname), "..", "package.json"), "utf8"));
4035
- return pkg.version ?? "0.0.0";
4036
- }
4037
- catch {
4038
- return "0.0.0";
4039
- }
4098
+ return getAppVersion() || "0.0.0";
4040
4099
  }
4041
4100
  async checkUpdate() {
4042
4101
  try {
@@ -4353,7 +4412,7 @@ export class DshClientSession {
4353
4412
  .join("\n");
4354
4413
  const prev = this.conv;
4355
4414
  // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
4356
- prev.listed = prev.isStreaming || prev.terminals.countBlockingLive() > 0 || prev.promptedSinceActive;
4415
+ prev.listed = this.shouldRetainDshConversation(prev);
4357
4416
  this.activeId = fresh.id;
4358
4417
  // 编辑后的提问本身在 prompt 里;历史作为附加上下文(首条 prompt)。
4359
4418
  const headText = contextNote.trim()
@@ -4459,11 +4518,7 @@ export class DshClientSession {
4459
4518
  // 旧 active 会话:活跃的(流式/有终端/跑过)标 listed → 后台运行可见
4460
4519
  // (与 pi 的 displaceActive 语义一致);空白的直接弃(不列)。
4461
4520
  const prev = this.conv;
4462
- prev.listed =
4463
- prev.isStreaming ||
4464
- prev.terminals.countBlockingLive() > 0 ||
4465
- prev.promptedSinceActive ||
4466
- prev.messages.length > 0;
4521
+ prev.listed = this.shouldRetainDshConversation(prev) || prev.messages.length > 0;
4467
4522
  // 新项目 → 新会话。
4468
4523
  this.activeId = this.addConversation(`web-${randomUUID().slice(0, 12)}`, abs, false).id;
4469
4524
  // 旧项目非活跃 conversation 回收(pi 的 displaceActive 语义:切走后
@@ -4573,7 +4628,7 @@ export class DshAgentService {
4573
4628
  constructor(cwd, stateFile, dataDir, agentDir) {
4574
4629
  this.cwd = cwd;
4575
4630
  this.agentDir = agentDir;
4576
- this.stateStore = new ClientStateStore(stateFile);
4631
+ this.stateStore = typeof stateFile === "string" ? new ClientStateStore(stateFile) : stateFile;
4577
4632
  this.dataDir = dataDir;
4578
4633
  }
4579
4634
  isQuiesced() {
@@ -25,6 +25,7 @@
25
25
  */
26
26
  import { parseTextQuote } from "../text-quote.js";
27
27
  import { ARGS_CAP, TEXT_CAP, TOOL_OUTPUT_CAP, truncate } from "../serialize.js";
28
+ import { stripMarkers } from "../markers/index.js";
28
29
  /** DSH user-role content blocks → UiContentBlock[]。 */
29
30
  export function serializeUserBlocks(blocks) {
30
31
  if (!Array.isArray(blocks) || blocks.length === 0) {
@@ -38,6 +39,16 @@ export function serializeUserBlocks(blocks) {
38
39
  return { type: "text", text: String(b?.text ?? "") };
39
40
  });
40
41
  }
42
+ /** 提取 DSH assistant 事件中的原始未剥离文本(供 MarkerService 解析内联标记)。 */
43
+ export function extractDshAssistantRawText(data) {
44
+ const blocks = data.message?.content;
45
+ if (!Array.isArray(blocks))
46
+ return "";
47
+ return blocks
48
+ .filter((b) => b?.type === "text" && typeof b.text === "string")
49
+ .map((b) => b.text)
50
+ .join("\n");
51
+ }
41
52
  /** DSH assistant-role content blocks → UiContentBlock[]。 */
42
53
  export function serializeAssistantBlocks(blocks) {
43
54
  if (!Array.isArray(blocks))
@@ -45,7 +56,8 @@ export function serializeAssistantBlocks(blocks) {
45
56
  return blocks.map((b) => {
46
57
  switch (b?.type) {
47
58
  case "text": {
48
- const { text, truncated } = truncate(b.text ?? "", TEXT_CAP);
59
+ const cleaned = stripMarkers(b.text ?? "");
60
+ const { text, truncated } = truncate(cleaned, TEXT_CAP);
49
61
  return { type: "text", text, truncated };
50
62
  }
51
63
  case "reasoning": {
@@ -236,6 +248,9 @@ export class DshStreamAccumulator {
236
248
  if (b.type === "toolCall" && (b.argumentsText ?? "") === "") {
237
249
  out.push({ type: "toolCall", id: b.id, name: b.name });
238
250
  }
251
+ else if (b.type === "text") {
252
+ out.push({ ...b, text: stripMarkers(String(b.text ?? ""), { stripTrailingIncomplete: true }) });
253
+ }
239
254
  else {
240
255
  out.push(b);
241
256
  }
@@ -33,8 +33,13 @@ export function windowsBashPath() {
33
33
  export function hasGitBash() {
34
34
  const pf = process.env.ProgramFiles;
35
35
  const pf86 = process.env["ProgramFiles(x86)"];
36
- for (const cand of [pf ? join(pf, "Git", "bin", "bash.exe") : "", pf86 ? join(pf86, "Git", "bin", "bash.exe") : ""]) {
37
- if (cand && existsSync(cand))
36
+ for (const cand of [
37
+ process.env.PI_WEB_SHELL ?? "",
38
+ process.env.SHELL ?? "",
39
+ pf ? join(pf, "Git", "bin", "bash.exe") : "",
40
+ pf86 ? join(pf86, "Git", "bin", "bash.exe") : "",
41
+ ]) {
42
+ if (cand && existsSync(cand) && cand.toLowerCase().includes("bash"))
38
43
  return true;
39
44
  }
40
45
  return false;