pi-web-ui 0.119.0 → 0.120.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 (136) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/bin/hub-upgrade.mjs +33 -15
  3. package/bin/lib/atomic-file.mjs +90 -0
  4. package/dist/server/agent-service-daemon.js +44 -10
  5. package/dist/server/agent-service.js +803 -106
  6. package/dist/server/atomic-file.js +130 -5
  7. package/dist/server/bash-timeout.js +15 -0
  8. package/dist/server/bash-tool.js +68 -4
  9. package/dist/server/bg-servers.js +19 -13
  10. package/dist/server/canvas/canvas-dispatch.js +12 -1
  11. package/dist/server/client-state.js +56 -14
  12. package/dist/server/conversation-tool.js +3 -2
  13. package/dist/server/delegate-task.js +8 -8
  14. package/dist/server/device-center/group-router-runtime.js +2 -0
  15. package/dist/server/device-center/hub-upgrade.js +5 -10
  16. package/dist/server/dispatch-domain-handlers.js +96 -22
  17. package/dist/server/dispatch-plugin-handlers.js +10 -0
  18. package/dist/server/dsh/dsh-agent-service.js +9 -9
  19. package/dist/server/durable/durable-agent-service.js +1 -1
  20. package/dist/server/files-service.js +41 -19
  21. package/dist/server/fs-copy.js +93 -0
  22. package/dist/server/goal-review-gate.js +2 -2
  23. package/dist/server/index.js +15 -0
  24. package/dist/server/job-runner.js +345 -0
  25. package/dist/server/marker-service.js +42 -26
  26. package/dist/server/model-session.js +16 -0
  27. package/dist/server/phone-tool.js +167 -0
  28. package/dist/server/plan-mode.js +2 -2
  29. package/dist/server/plugin-api-catalog.js +1 -1
  30. package/dist/server/plugin-bundled.js +35 -28
  31. package/dist/server/plugin-installer.js +15 -0
  32. package/dist/server/plugin-manifest-validate.js +10 -0
  33. package/dist/server/plugin-materialize.js +161 -0
  34. package/dist/server/plugin-paths.js +60 -0
  35. package/dist/server/plugin-removal.js +16 -3
  36. package/dist/server/plugin-schedule.js +8 -7
  37. package/dist/server/plugin-secrets.js +7 -3
  38. package/dist/server/plugin-updater.js +2 -4
  39. package/dist/server/plugins.js +74 -38
  40. package/dist/server/preset-fields.js +9 -9
  41. package/dist/server/process-utils.js +11 -0
  42. package/dist/server/project-scripts.js +38 -0
  43. package/dist/server/prompt-composer.js +40 -21
  44. package/dist/server/protocol-version.js +1 -1
  45. package/dist/server/quick-ask.js +3 -0
  46. package/dist/server/remote-ssh-service.js +39 -0
  47. package/dist/server/scm-commitmsg.js +2 -1
  48. package/dist/server/serialize.js +8 -0
  49. package/dist/server/session-list-index.js +246 -0
  50. package/dist/server/session-list-scan.js +5 -0
  51. package/dist/server/session-parser.js +16 -0
  52. package/dist/server/settings-service.js +39 -6
  53. package/dist/server/subagent-budget.js +68 -0
  54. package/dist/server/subagent-evidence.js +297 -0
  55. package/dist/server/subagent-helpers.js +12 -0
  56. package/dist/server/subagent-ledger.js +401 -0
  57. package/dist/server/subagent-notify.js +6 -2
  58. package/dist/server/subagent-security-gate.js +2 -2
  59. package/dist/server/subagent-settle.js +71 -0
  60. package/dist/server/subagents.js +497 -79
  61. package/dist/server/tabs.js +8 -1
  62. package/dist/server/terminals.js +0 -1
  63. package/dist/server/tool-manager.js +90 -16
  64. package/dist/server/tool-prompts.js +5 -1
  65. package/dist/server/universal/universal-service.js +1 -1
  66. package/dist/server/universal/universal-session.js +45 -7
  67. package/dist/server/vision-bridge.js +2 -0
  68. package/dist/server/workspace-handle.js +119 -17
  69. package/dist/server/workspace-queue.js +37 -0
  70. package/docs/README.md +25 -23
  71. package/docs/architecture-plugins.md +23 -3
  72. package/docs/device-center.md +1 -1
  73. package/package.json +15 -3
  74. package/plugins/catalog.json +13 -2
  75. package/themes/bases/flow-base.css +7 -16
  76. package/web/dist/.build-assets.json +1 -1
  77. package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
  78. package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
  79. package/web/dist/assets/{CanvasStudio-2ydYbnpW.js → CanvasStudio-BB_Iq7pl.js} +3 -3
  80. package/web/dist/assets/{CanvasStudio-DizWvRjn.js → CanvasStudio-DU6O3N4u.js} +3 -3
  81. package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
  82. package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
  83. package/web/dist/assets/{DeviceExecutionSettings-B7R9ONaq.js → DeviceExecutionSettings-qJzbI0Cf.js} +1 -1
  84. package/web/dist/assets/{DeviceGroups-DFU4cv5b.js → DeviceGroups-DPrQxW6B.js} +1 -1
  85. package/web/dist/assets/{DeviceGroups-DoaQcxKj.js → DeviceGroups-DoucyUjI.js} +1 -1
  86. package/web/dist/assets/{Dropdown-Btjt6Dzh.js → Dropdown-kj_NIj6e.js} +1 -1
  87. package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
  88. package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
  89. package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
  90. package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
  91. package/web/dist/assets/{GroupConversation-DwZZrMuE.js → GroupConversation-1-lsPO1f.js} +3 -3
  92. package/web/dist/assets/{GroupConversation-KOi8sa5b.js → GroupConversation-HeiyW_O_.js} +3 -3
  93. package/web/dist/assets/{GroupWorkItems-FqAL74bC.js → GroupWorkItems-BYJv2XFj.js} +1 -1
  94. package/web/dist/assets/{HintTip-BOwPzBGR.js → HintTip-DFhoclDw.js} +1 -1
  95. package/web/dist/assets/{ModelConfigModal-DLIfWKdB.js → ModelConfigModal-D2Ro-jUZ.js} +2 -2
  96. package/web/dist/assets/{ModelConfigModal-B140kWrs.js → ModelConfigModal-DPc9R1pq.js} +2 -2
  97. package/web/dist/assets/{NativeCliPanel-BwiLazSq.js → NativeCliPanel-B108d697.js} +3 -3
  98. package/web/dist/assets/{NativeCliPanel-U0F_EfAU.js → NativeCliPanel-DupvGwQM.js} +3 -3
  99. package/web/dist/assets/{PiSetupModal-Dc7EQ4L3.js → PiSetupModal-D0HitBfd.js} +1 -1
  100. package/web/dist/assets/{ProviderOAuthControls-C3opmPhu.js → ProviderOAuthControls-BLKUEDde.js} +1 -1
  101. package/web/dist/assets/{SCMPanel-BBxQfmq9.js → SCMPanel-DDbWrUHR.js} +1 -1
  102. package/web/dist/assets/{SCMPanel-D2t97Vvr.js → SCMPanel-DluNcd2-.js} +1 -1
  103. package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
  104. package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
  105. package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
  106. package/web/dist/assets/{TermXterm-B6nCtO2b.js → TermXterm-SYc-MUk2.js} +1 -1
  107. package/web/dist/assets/{TerminalPanel-BWB3iSeN.js → TerminalPanel-CgA_lhVT.js} +1 -1
  108. package/web/dist/assets/{TerminalPanel-CAV2SosY.js → TerminalPanel-vdSIOPjD.js} +1 -1
  109. package/web/dist/assets/{TuiOverlayModal-B0jBPOMc.js → TuiOverlayModal-Cy1jYYIw.js} +1 -1
  110. package/web/dist/assets/{TuiOverlayModal-DGd6fzU6.js → TuiOverlayModal-kXY_4hV8.js} +1 -1
  111. package/web/dist/assets/{app-globals-CR8Ls9nE.js → app-globals-CBEscsYP.js} +9 -9
  112. package/web/dist/assets/{canvas-client-B0lkqTtF.js → canvas-client-Clsypfs6.js} +1 -1
  113. package/web/dist/assets/{desktop-BME3DkyE.js → desktop-C6D9a8HZ.js} +1 -1
  114. package/web/dist/assets/index-BD29OL9L.js +404 -0
  115. package/web/dist/assets/index-BlCxbqqr.js +404 -0
  116. package/web/dist/assets/index-DB55rbKC.css +1 -0
  117. package/web/dist/assets/{plugin-host-CVgcdBOk.js → plugin-host-VWBcq-LQ.js} +1 -1
  118. package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
  119. package/web/dist/assets/theme-CpQk_Agp.js +1 -0
  120. package/web/dist/index.html +10 -10
  121. package/web/dist/sw.js +1 -1
  122. package/web/dist/assets/BgTasksModal-CVHW1lRA.js +0 -1
  123. package/web/dist/assets/BgTasksModal-t5hxW1H6.js +0 -1
  124. package/web/dist/assets/DeviceCenter-CPaZNBJE.js +0 -3
  125. package/web/dist/assets/DeviceCenter-DsVakAYR.js +0 -3
  126. package/web/dist/assets/FilePreview-QGQfD2lV.js +0 -2
  127. package/web/dist/assets/FilePreview-qez9walH.js +0 -2
  128. package/web/dist/assets/GlobalSearchModal-B-cnTDJ5.js +0 -1
  129. package/web/dist/assets/GlobalSearchModal-BvbafjdU.js +0 -1
  130. package/web/dist/assets/SettingsModal-BqPQNUwF.js +0 -34
  131. package/web/dist/assets/SettingsModal-l7eeV-Rq.js +0 -34
  132. package/web/dist/assets/index-BBAQNi6v.js +0 -404
  133. package/web/dist/assets/index-BYW9d61A.js +0 -404
  134. package/web/dist/assets/index-BYWs88H2.css +0 -1
  135. package/web/dist/assets/remote-ssh-client-DEpvwgqG.js +0 -1
  136. package/web/dist/assets/theme-DVa7Z5Zu.js +0 -1
@@ -3,6 +3,7 @@ import { getGlobalRemoteSshService, isRemoteWorkspaceUri } from "./remote-ssh-se
3
3
  import { prepareRemoteNativeCliPaste } from "./native-cli-remote-files.js";
4
4
  import { remoteNativeCliCleanupQueue } from "./native-cli-remote-cleanup.js";
5
5
  import { normalizePathKey } from "./client-state.js";
6
+ import { runWorkspaceCommand } from "./workspace-queue.js";
6
7
  import { prepareNativeCliPaste } from "./native-cli.js";
7
8
  export function handleFileMessage(msg, cs) {
8
9
  switch (msg.type) {
@@ -10,7 +11,7 @@ export function handleFileMessage(msg, cs) {
10
11
  void cs.listFiles(msg.path);
11
12
  return true;
12
13
  case "search_files":
13
- void cs.searchFiles(msg.query, msg.reqId);
14
+ void cs.searchFiles(msg.query, msg.reqId, msg.scope);
14
15
  return true;
15
16
  case "read_file":
16
17
  void cs.readFile(msg.path);
@@ -43,17 +44,30 @@ export function handleFileMessage(msg, cs) {
43
44
  void cs.completePath(msg.path);
44
45
  return true;
45
46
  case "make_dir":
46
- void cs.makeDir(msg.path, msg.setAsCwd === true);
47
+ // 新建目录并设为工作区 = 一次工作区绑定,入队保持与后续建会话/切会话的先后顺序。
48
+ if (msg.setAsCwd === true) {
49
+ void runWorkspaceCommand(cs, async () => {
50
+ try {
51
+ await cs.makeDir(msg.path, true);
52
+ }
53
+ catch (err) {
54
+ cs.emitNotice("error", `创建目录失败:${err.message}`, `Failed to create directory: ${err.message}`);
55
+ }
56
+ });
57
+ }
58
+ else
59
+ void cs.makeDir(msg.path, false);
47
60
  return true;
48
61
  case "set_cwd":
49
- void (async () => {
62
+ // 入队(见 workspace-queue):后续工作区命令(建会话 / 切会话)会等它落定,不会拿旧 cwd 开工。
63
+ void runWorkspaceCommand(cs, async () => {
50
64
  try {
51
65
  await cs.setCwd(msg.path);
52
66
  }
53
67
  catch (err) {
54
68
  cs.emitNotice("error", `切换工作目录失败:${err.message}`, `Failed to switch workspace: ${err.message}`);
55
69
  }
56
- })();
70
+ });
57
71
  return true;
58
72
  case "set_workspace_roots":
59
73
  void (async () => {
@@ -66,7 +80,8 @@ export function handleFileMessage(msg, cs) {
66
80
  })();
67
81
  return true;
68
82
  case "create_sandbox":
69
- void (async () => {
83
+ // 沙盒创建末尾会 setCwd(工作区换到沙盒里),所以它在队列里占位,后续建会话排在它之后。
84
+ void runWorkspaceCommand(cs, async () => {
70
85
  try {
71
86
  await cs.createSandbox?.({
72
87
  name: msg.name,
@@ -77,16 +92,16 @@ export function handleFileMessage(msg, cs) {
77
92
  catch (err) {
78
93
  cs.emitNotice("error", `创建沙盒失败:${err.message}`, `Failed to create sandbox: ${err.message}`);
79
94
  }
80
- })();
95
+ });
81
96
  return true;
82
97
  case "reset_sandbox":
83
- void cs.resetSandbox?.(msg.path);
98
+ void runWorkspaceCommand(cs, () => cs.resetSandbox?.(msg.path));
84
99
  return true;
85
100
  case "persist_sandbox":
86
- void cs.persistSandbox?.(msg.path);
101
+ void runWorkspaceCommand(cs, () => cs.persistSandbox?.(msg.path));
87
102
  return true;
88
103
  case "promote_sandbox":
89
- void cs.promoteSandbox?.(msg.targetPath, msg.path, msg.switchToTarget);
104
+ void runWorkspaceCommand(cs, () => cs.promoteSandbox?.(msg.targetPath, msg.path, msg.switchToTarget));
90
105
  return true;
91
106
  case "diff_sandbox":
92
107
  void cs.diffSandbox?.(msg.path, msg.requestId);
@@ -153,6 +168,15 @@ export function handleBgServerMessage(msg, cs) {
153
168
  case "list_bg_servers":
154
169
  void cs.listBgServers();
155
170
  return true;
171
+ case "project_scripts":
172
+ cs.listProjectScripts?.(msg.cwd);
173
+ return true;
174
+ case "start_bg_script":
175
+ cs.startBgScript?.(msg.script, msg.cwd);
176
+ return true;
177
+ case "restart_bg_job":
178
+ cs.restartBgJob?.(msg.taskId);
179
+ return true;
156
180
  case "set_bg_keep":
157
181
  cs.setBackgroundKeep(msg.port, msg.keep);
158
182
  return true;
@@ -583,12 +607,34 @@ export function handleSessionLifecycleMessage(msg, cs, send, daemon, clientId) {
583
607
  acknowledge();
584
608
  return true;
585
609
  }
586
- const pending = msg.type === "new_cli_chat"
587
- ? cs.newCliChat?.(msg.config, msg.cwd, acknowledge)
588
- : cs.newChat(msg.preset, msg.ephemeral, acknowledge, msg.independent);
589
- void Promise.resolve(pending)
590
- .then(() => acknowledge())
591
- .catch(() => acknowledge());
610
+ // 工作区绑定一律入队(顺序 = 到达顺序):先切目录再建会话、或 client 直接声明 cwd,
611
+ // 都保证 newChat() 读到的是目标工作区。声明了 cwd 却切不过去就不建会话(#872)。
612
+ void runWorkspaceCommand(cs, async () => {
613
+ if (msg.type === "new_chat") {
614
+ const target = (msg.cwd ?? "").trim();
615
+ if (target && normalizePathKey(target) !== normalizePathKey(cs.cwd)) {
616
+ try {
617
+ await cs.setCwd(target);
618
+ }
619
+ catch {
620
+ // 失败由下面的核验统一报:能切就是好,切不过去就不建会话、给出回执
621
+ }
622
+ if (normalizePathKey(target) !== normalizePathKey(cs.cwd)) {
623
+ send?.({
624
+ type: "notice",
625
+ level: "error",
626
+ text: `新建对话失败:没能切换到工作目录 ${target}`,
627
+ textEn: `Failed to create chat: could not switch the workspace to ${target}`,
628
+ });
629
+ return;
630
+ }
631
+ }
632
+ }
633
+ const pending = msg.type === "new_cli_chat"
634
+ ? cs.newCliChat?.(msg.config, msg.cwd, acknowledge)
635
+ : cs.newChat(msg.preset, msg.ephemeral, acknowledge, msg.independent);
636
+ await Promise.resolve(pending);
637
+ }).then(() => acknowledge(), () => acknowledge());
592
638
  return true;
593
639
  }
594
640
  case "delete_message":
@@ -606,10 +652,10 @@ export function handleSessionLifecycleMessage(msg, cs, send, daemon, clientId) {
606
652
  void cs.editMessage(msg.messageId, msg.text, msg.attachments);
607
653
  return true;
608
654
  case "fork_session":
609
- void cs.forkSession?.(msg.messageId, msg.position, msg.conversationId);
655
+ void runWorkspaceCommand(cs, () => cs.forkSession?.(msg.messageId, msg.position, msg.conversationId));
610
656
  return true;
611
657
  case "rollback_session":
612
- void cs.rollbackSession?.(msg.messageId, msg.conversationId, msg.restoreWorkspace);
658
+ void runWorkspaceCommand(cs, () => cs.rollbackSession?.(msg.messageId, msg.conversationId, msg.restoreWorkspace));
613
659
  return true;
614
660
  case "list_sessions":
615
661
  if (typeof msg.limit === "number")
@@ -657,10 +703,10 @@ export function handleSessionLifecycleMessage(msg, cs, send, daemon, clientId) {
657
703
  void cs.dismissFinishedSubagents(msg.parentId);
658
704
  return true;
659
705
  case "switch_session":
660
- void cs.switchSession(msg.path, msg.sessionId, msg.independent);
706
+ void runWorkspaceCommand(cs, () => cs.switchSession(msg.path, msg.sessionId, msg.independent));
661
707
  return true;
662
708
  case "switch_conversation":
663
- void cs.switchConversation(msg.id);
709
+ void runWorkspaceCommand(cs, () => cs.switchConversation(msg.id));
664
710
  return true;
665
711
  case "search_sessions":
666
712
  void cs.searchSessions(msg.query, msg.reqId);
@@ -807,8 +853,9 @@ export function handleSettingsMessage(msg, cs, send) {
807
853
  case "get_settings":
808
854
  cs.refreshSettings();
809
855
  return true;
810
- case "set_settings":
811
- void cs.setSettings({
856
+ case "set_settings": {
857
+ // 同步抛错与 Promise 拒绝都要回告前端;实现可能是同步 mock(返回 undefined)
858
+ const saving = cs.setSettings({
812
859
  promptMode: msg.promptMode,
813
860
  customSystemPrompt: msg.customSystemPrompt,
814
861
  promptTemplate: msg.promptTemplate,
@@ -880,7 +927,6 @@ export function handleSettingsMessage(msg, cs, send) {
880
927
  autoCompactionInstructions: msg.autoCompactionInstructions,
881
928
  reviewPrompt: msg.reviewPrompt,
882
929
  reviewDisabledSkills: msg.reviewDisabledSkills,
883
- markersEnabled: msg.markersEnabled,
884
930
  disabledMarkers: msg.disabledMarkers,
885
931
  quickPhrases: msg.quickPhrases,
886
932
  quickPhrasesEnabled: msg.quickPhrasesEnabled,
@@ -890,7 +936,17 @@ export function handleSettingsMessage(msg, cs, send) {
890
936
  quickPhrasesSeeded: msg.quickPhrasesSeeded,
891
937
  uiLayout: msg.uiLayout,
892
938
  });
939
+ void Promise.resolve(saving).catch((error) => {
940
+ // 保存失败必须回告前端:否则面板只能靠超时猜,用户永远不知道改没生效
941
+ send?.({
942
+ type: "notice",
943
+ level: "error",
944
+ text: `设置保存失败,修改未生效:${error instanceof Error ? error.message : String(error)}`,
945
+ textEn: `Settings were not saved: ${error instanceof Error ? error.message : String(error)}`,
946
+ });
947
+ });
893
948
  return true;
949
+ }
894
950
  case "extensions_reload":
895
951
  void cs.reloadExtensions();
896
952
  return true;
@@ -993,6 +1049,9 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
993
1049
  case "page_response":
994
1050
  cs.resolvePageCall?.(msg.id, msg.ok, msg.result, msg.error);
995
1051
  return true;
1052
+ case "phone_response":
1053
+ cs.resolvePhoneCall?.(msg.id, msg.ok, msg.result, msg.error);
1054
+ return true;
996
1055
  default:
997
1056
  return false;
998
1057
  }
@@ -1009,6 +1068,21 @@ export function handleRemoteSshMessage(msg, remoteSshSvc, send) {
1009
1068
  });
1010
1069
  })();
1011
1070
  return true;
1071
+ case "remote_ssh_trust_host":
1072
+ void (async () => {
1073
+ const res = await remoteSshSvc.trustHostKey({
1074
+ host: msg.host,
1075
+ port: msg.port,
1076
+ fingerprint: msg.fingerprint,
1077
+ replace: msg.replace,
1078
+ });
1079
+ send({
1080
+ type: "remote_ssh_trust_host_result",
1081
+ reqId: msg.reqId,
1082
+ ...res,
1083
+ });
1084
+ })();
1085
+ return true;
1012
1086
  case "remote_ssh_list_dir":
1013
1087
  void (async () => {
1014
1088
  const res = await remoteSshSvc.listDir(msg.connectionId, msg.path);
@@ -111,6 +111,16 @@ export function handlePluginMessage(msg, ctx) {
111
111
  emit: (m) => send(m),
112
112
  done: async (ok, info) => {
113
113
  if (ok) {
114
+ // 安装即启用:出厂默认把一批插件放在 disabledPlugins 里,不摘掉会变成「装了却找不到」
115
+ if (jobAction === "install") {
116
+ try {
117
+ await cs?.enableInstalledPlugin?.(pluginId);
118
+ }
119
+ catch (err) {
120
+ // 设置落盘失败时 commitSettings 已发过错误 notice,这里不阻断后面的重载与成功回执
121
+ console.warn(`[plugins] enable after install failed (${pluginId}):`, err);
122
+ }
123
+ }
114
124
  await reloadPluginsAndPush(jobLang);
115
125
  if (typeof cs?.checkPluginUpdates === "function") {
116
126
  void cs.checkPluginUpdates(false);
@@ -1619,6 +1619,9 @@ export class DshClientSession {
1619
1619
  }
1620
1620
  if (this.conv !== conv || this.switchingWorkspace)
1621
1621
  return;
1622
+ // 真的发消息才算「项目最近对话」:左栏项目排序只认这个,浏览/切换不刷新
1623
+ this.stateStore.remember(this.clientId, conv.cwd);
1624
+ void this.pushProjects().catch(() => { });
1622
1625
  this.markerSvc.clearActions(conv.id);
1623
1626
  const fileOwner = this.findSessionOwnerById?.(conv.sessionId);
1624
1627
  if (fileOwner && fileOwner.isStreaming) {
@@ -2961,8 +2964,8 @@ export class DshClientSession {
2961
2964
  async listFiles(relPath) {
2962
2965
  await this.files.listFiles(relPath);
2963
2966
  }
2964
- async searchFiles(query, reqId) {
2965
- await this.files.searchFiles(query, reqId);
2967
+ async searchFiles(query, reqId, scope) {
2968
+ await this.files.searchFiles(query, reqId, scope);
2966
2969
  }
2967
2970
  async searchSessions(query, reqId) {
2968
2971
  const q = query.trim().toLowerCase();
@@ -3466,7 +3469,6 @@ export class DshClientSession {
3466
3469
  reviewSkills: [],
3467
3470
  extensions: [],
3468
3471
  presets: this.stateStore.getPresets(this.clientId).map(settingsPresetToUi),
3469
- markersEnabled: this.markerSvc.current.markersEnabled,
3470
3472
  disabledMarkers: [...this.markerSvc.current.disabledMarkers],
3471
3473
  markers: this.markerSvc.listForUi(),
3472
3474
  subagentTemplates: [],
@@ -3552,10 +3554,8 @@ export class DshClientSession {
3552
3554
  if (partial.preserveDraftAcrossConversations !== undefined)
3553
3555
  this.settings.preserveDraftAcrossConversations = partial.preserveDraftAcrossConversations;
3554
3556
  const prevMarkerGuidance = this.markerSvc.buildGuidance();
3555
- this.markerSvc.setAll({
3556
- markersEnabled: partial.markersEnabled,
3557
- disabledMarkers: partial.disabledMarkers,
3558
- });
3557
+ if (partial.disabledMarkers !== undefined)
3558
+ this.markerSvc.setDisabledMarkers(partial.disabledMarkers);
3559
3559
  const markerGuidanceChanged = this.markerSvc.buildGuidance() !== prevMarkerGuidance;
3560
3560
  this.stateStore.saveSettings(this.clientId, {
3561
3561
  nativeCliInheritModel: partial.nativeCliInheritModel,
@@ -4900,7 +4900,7 @@ export class DshClientSession {
4900
4900
  }
4901
4901
  this.cwd = abs;
4902
4902
  this.roots = this.stateStore.getWorkspaceRoots(this.clientId, abs);
4903
- this.stateStore.remember(this.clientId, abs);
4903
+ this.stateStore.remember(this.clientId, abs, { promote: false });
4904
4904
  const prev = this.conv;
4905
4905
  prev.listed = this.shouldRetainDshConversation(prev) || prev.messages.length > 0;
4906
4906
  const openRecent = this.settings.openRecentSessionOnProjectSwitch ?? true;
@@ -5312,7 +5312,7 @@ export class DshAgentService {
5312
5312
  }
5313
5313
  cs = DshClientSession.create(clientId, cwd, this.stateStore, this.dataDir, this.agentDir);
5314
5314
  this.clients.set(clientId, cs);
5315
- this.stateStore.remember(clientId, cwd);
5315
+ this.stateStore.remember(clientId, cwd, { promote: false });
5316
5316
  if (cwd !== this.cwd) {
5317
5317
  send({
5318
5318
  type: "notice",
@@ -36,7 +36,7 @@ export class DurableAgentService {
36
36
  catch { }
37
37
  }
38
38
  if (typeof this.stateStore?.remember === "function") {
39
- this.stateStore.remember(clientId, effectiveCwd);
39
+ this.stateStore.remember(clientId, effectiveCwd, { promote: false });
40
40
  }
41
41
  const driver = new DurableAgentDriver(effectiveCwd, { dataDir: this.dataDir, agentDir: this.agentDir });
42
42
  session = new UniversalSession({
@@ -315,10 +315,10 @@ export class FilesService {
315
315
  * with a search_files_result echoing reqId so the client's request never
316
316
  * stalls (ok:false on unexpected failure).
317
317
  */
318
- async searchFiles(query, reqId) {
318
+ async searchFiles(query, reqId, scope) {
319
319
  const activeCwd = this.host.getActiveCwd();
320
320
  if (isRemoteWorkspaceUri(activeCwd)) {
321
- await this.searchRemoteFiles(activeCwd, query, reqId);
321
+ await this.searchRemoteFiles(activeCwd, query, reqId, scope);
322
322
  return;
323
323
  }
324
324
  const { join } = await import("node:path");
@@ -329,6 +329,18 @@ export class FilesService {
329
329
  return;
330
330
  }
331
331
  const root = resolve(activeCwd);
332
+ const normScope = (scope ?? "").trim().replace(/\\/g, "/").replace(/\/+$/, "");
333
+ let walkAbs = root;
334
+ let walkRel = "";
335
+ if (normScope !== "" && normScope !== "@root") {
336
+ const scopeAbs = resolve(root, normScope);
337
+ const rawRel = relative(root, scopeAbs);
338
+ if (rawRel !== ".." && !rawRel.startsWith(`..${sep}`) && !rawRel.includes(`${sep}..`)) {
339
+ walkAbs = scopeAbs;
340
+ walkRel = rawRel.split(sep).join("/");
341
+ }
342
+ }
343
+ const inScope = (p) => walkRel === "" || p === walkRel || p.startsWith(`${walkRel}/`);
332
344
  const ignored = ignoredEntries();
333
345
  const MAX_RESULTS = 50;
334
346
  const MAX_VISITED = 20000;
@@ -350,22 +362,25 @@ export class FilesService {
350
362
  : join(home, normQuery.slice(2))
351
363
  : wireToAbs(normQuery);
352
364
  const st = await fsp.stat(targetAbs).catch(() => null);
353
- if (st) {
365
+ // 目录也要收:输入框里敲一个目录路径时,结果表要能直接打开它(`type: "dir"` 曾经不可达)。
366
+ if (st && (st.isFile() || st.isDirectory())) {
354
367
  const wp = workspacePath(root, targetAbs);
355
368
  const wirePath = wp ? wp.rel : targetAbs.split(sep).join("/");
356
- const baseName = targetAbs.split(/[\\/]/).pop() || wirePath;
357
- results.push({
358
- path: wirePath,
359
- name: baseName,
360
- type: st.isDirectory() ? "dir" : "file",
361
- });
369
+ if (inScope(wirePath)) {
370
+ const baseName = targetAbs.split(/[\\/]/).pop() || wirePath;
371
+ results.push({
372
+ path: wirePath,
373
+ name: baseName,
374
+ type: st.isDirectory() ? "dir" : "file",
375
+ });
376
+ }
362
377
  }
363
378
  }
364
379
  else {
365
380
  const directWp = workspacePath(root, normQuery);
366
381
  if (directWp) {
367
382
  const st = await fsp.stat(directWp.abs).catch(() => null);
368
- if (st) {
383
+ if (st && (st.isFile() || st.isDirectory()) && inScope(directWp.rel)) {
369
384
  const baseName = directWp.abs.split(/[\\/]/).pop() || directWp.rel;
370
385
  results.push({
371
386
  path: directWp.rel,
@@ -410,6 +425,8 @@ export class FilesService {
410
425
  }
411
426
  const childRelLower = childRel.toLowerCase();
412
427
  const nameLower = d.name.toLowerCase();
428
+ // 目录命中同样要有结果(前端按树展开后可直达),只是不能吃掉 50 条预算:
429
+ // 目录照常入列,仍然继续下潜。
413
430
  if ((nameLower.includes(q) || childRelLower.includes(q)) && !results.some((r) => r.path === childRel)) {
414
431
  results.push({
415
432
  path: childRel,
@@ -423,7 +440,7 @@ export class FilesService {
423
440
  }
424
441
  };
425
442
  try {
426
- await walk(root, "", 0);
443
+ await walk(walkAbs, walkRel, 0);
427
444
  this.host.emit({
428
445
  type: "search_files_result",
429
446
  reqId,
@@ -1556,7 +1573,7 @@ export class FilesService {
1556
1573
  this.emitListError(targetAbs, e.message || String(err), e.code);
1557
1574
  }
1558
1575
  }
1559
- async searchRemoteFiles(rawCwd, query, reqId) {
1576
+ async searchRemoteFiles(rawCwd, query, reqId, scope) {
1560
1577
  const rawQuery = query.trim();
1561
1578
  if (!rawQuery) {
1562
1579
  this.host.emit({ type: "search_files_result", reqId, ok: true, results: [] });
@@ -1570,18 +1587,22 @@ export class FilesService {
1570
1587
  try {
1571
1588
  const normQuery = rawQuery.replace(/\\/g, "/");
1572
1589
  const q = normQuery.toLowerCase();
1590
+ const normScope = (scope ?? "").trim();
1591
+ const inScope = (p) => normScope === "" || p === normScope || p.startsWith(normScope + "/");
1573
1592
  const results = [];
1574
1593
  let truncated = false;
1575
1594
  const target = this.resolveRemoteTarget(rawCwd, normQuery);
1576
- if (target) {
1595
+ if (target && inScope(target.rel)) {
1577
1596
  try {
1578
1597
  const st = await sshSvc.sftpStat(rawCwd, target.abs);
1579
- const name = posix.basename(target.abs) || target.rel;
1580
- results.push({
1581
- path: target.rel,
1582
- name,
1583
- type: st.isDirectory ? "dir" : "file",
1584
- });
1598
+ if (!st.isDirectory) {
1599
+ const name = posix.basename(target.abs) || target.rel;
1600
+ results.push({
1601
+ path: target.rel,
1602
+ name,
1603
+ type: "file",
1604
+ });
1605
+ }
1585
1606
  }
1586
1607
  catch { }
1587
1608
  }
@@ -1594,6 +1615,7 @@ export class FilesService {
1594
1615
  continue;
1595
1616
  const name = posix.basename(clean);
1596
1617
  if ((name.toLowerCase().includes(q) || clean.toLowerCase().includes(q)) &&
1618
+ inScope(clean) &&
1597
1619
  !results.some((r) => r.path === clean)) {
1598
1620
  results.push({
1599
1621
  path: clean,
@@ -0,0 +1,93 @@
1
+ import { cpSync, lstatSync, readdirSync, rmSync, rmdirSync } from "node:fs";
2
+ import { dirname, isAbsolute, join, relative, sep } from "node:path";
3
+ /**
4
+ * 复制目录树的单源原语。
5
+ *
6
+ * 为什么必须集中一处:判据只在**相对路径**上生效才有意义。npm -g 安装时源目录自身就在
7
+ * `.../node_modules/pi-web-ui/plugins/<id>` 里,用绝对路径去匹配 `node_modules` 会把整棵树
8
+ * (连根带叶)全部过滤掉,得到一份空副本还以为成功(issue #856)。
9
+ */
10
+ /** 默认永不复制的内容:版本库元数据与可重装的依赖树 */
11
+ export const SKIP_VCS_AND_DEPS = [".git", "node_modules"];
12
+ export function toPosixPath(rel) {
13
+ return sep === "/" ? rel : rel.split(sep).join("/");
14
+ }
15
+ /** 相对路径里出现被跳过名字的任意一段即跳过;源根(`""`)永远放行 */
16
+ export function isSkippedPath(rel, skip) {
17
+ if (!rel)
18
+ return false;
19
+ return rel.split(/[\\/]/).some((part) => skip.includes(part));
20
+ }
21
+ export function copyTree(src, dst, opts = {}) {
22
+ const skip = opts.skip ?? SKIP_VCS_AND_DEPS;
23
+ cpSync(src, dst, {
24
+ recursive: true,
25
+ // 判据用相对路径:源根路径本身可能含 node_modules(全局安装布局)
26
+ filter: (from, to) => {
27
+ if (isSkippedPath(relative(src, from), skip))
28
+ return false;
29
+ // 只补缺:目录必须放行(否则整棵子树都进不来),已存在的文件一律不覆盖
30
+ if (!opts.missingOnly)
31
+ return true;
32
+ try {
33
+ return lstatSync(from).isDirectory() || !statExists(to);
34
+ }
35
+ catch {
36
+ return true;
37
+ }
38
+ },
39
+ });
40
+ }
41
+ function statExists(path) {
42
+ try {
43
+ lstatSync(path);
44
+ return true;
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
50
+ /** 列出目录树里的普通文件(posix 相对路径,已排序),跳过 `skip` 命中的目录 */
51
+ export function listTreeFiles(root, opts = {}) {
52
+ const skip = opts.skip ?? SKIP_VCS_AND_DEPS;
53
+ const out = [];
54
+ const walk = (dir) => {
55
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
56
+ if (skip.includes(entry.name))
57
+ continue;
58
+ const abs = join(dir, entry.name);
59
+ if (entry.isDirectory())
60
+ walk(abs);
61
+ else if (entry.isFile())
62
+ out.push(toPosixPath(relative(root, abs)));
63
+ }
64
+ };
65
+ walk(root);
66
+ return out.sort();
67
+ }
68
+ /** 删除 `stale` 列出的文件(只接受 root 内的相对路径),并顺手清理空出来的目录 */
69
+ export function pruneTreeFiles(root, stale) {
70
+ for (const rel of stale) {
71
+ if (!rel || isAbsolute(rel) || rel.split(/[\\/]/).includes(".."))
72
+ continue;
73
+ const abs = join(root, rel);
74
+ try {
75
+ rmSync(abs, { force: true });
76
+ }
77
+ catch {
78
+ continue;
79
+ }
80
+ let dir = dirname(abs);
81
+ while (dir !== root && dir.startsWith(root)) {
82
+ try {
83
+ if (readdirSync(dir).length)
84
+ break;
85
+ rmdirSync(dir);
86
+ }
87
+ catch {
88
+ break;
89
+ }
90
+ dir = dirname(dir);
91
+ }
92
+ }
93
+ }
@@ -157,8 +157,8 @@ export function goalReviewDenial(toolName, params) {
157
157
  }
158
158
  return {
159
159
  kind: "dispatch-tool",
160
- reason: `目标审查回合:不能调用 subagent(action="${act || "spawn"}") —— 轮次由服务端控制。请只做本轮审查、只回 verdict JSON。`,
161
- reasonEn: `Goal review round: subagent(action="${act || "spawn"}") is unavailable — the server owns the rounds. Just review this round and reply with only the verdict JSON.`,
160
+ reason: `目标审查回合:不能调用 conversation(action="${act || "spawn"}") —— 轮次由服务端控制。请只做本轮审查、只回 verdict JSON。`,
161
+ reasonEn: `Goal review round: conversation(action="${act || "spawn"}") is unavailable — the server owns the rounds. Just review this round and reply with only the verdict JSON.`,
162
162
  };
163
163
  }
164
164
  if (DISPATCH_TOOLS.has(name)) {
@@ -1414,6 +1414,21 @@ const service = {
1414
1414
  }
1415
1415
  return Promise.resolve();
1416
1416
  },
1417
+ /**
1418
+ * 关闭对话:pi 引擎走 daemon 的跨客户端路由(左栏 elsewhere / 离线残骸行都能删)。
1419
+ * 其他引擎的 `dismissConversation` 是本端语义(id, withFinished, force),不能当 daemon 路由用,
1420
+ * 直接退回请求方自己的会话。
1421
+ */
1422
+ async dismissConversation(clientId, msg) {
1423
+ const engine = ensureEngine(resolveClientEngine(clientId));
1424
+ if (engine instanceof AgentService)
1425
+ return engine.dismissConversation(clientId, msg);
1426
+ const cs = engine.get(clientId);
1427
+ if (!cs?.dismissConversation)
1428
+ return false;
1429
+ await cs.dismissConversation(msg.id, msg.withFinishedSubagents, msg.force);
1430
+ return true;
1431
+ },
1417
1432
  peekElsewhereQuestion(targetId, ownerId, convId) {
1418
1433
  const targetSvc = ensureEngine(resolveClientEngine(targetId));
1419
1434
  if (typeof targetSvc.peekElsewhereQuestion === "function") {