pi-web-ui 0.89.0 → 0.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,42 @@
8
8
  每个版本的内容按"实际合入该版本发布的提交"归档(以 `package.json` 的 version 变更提交为准),
9
9
  而不是按提交日期聚类——连续快速发布的 patch 版本以此为准最准确。
10
10
 
11
+ ## [Unreleased]
12
+
13
+ ## [0.90.0] — 2026-09-18
14
+
15
+ ### Added
16
+
17
+ - **手机端顶栏折叠** —— ≤768px 宽度时顶栏只保留 ☰ / 新对话 / 打开项目 / 📁,其余入口一律退进同一个「⋯」溢出菜单(与桌面端实测溢出走同一通道,不是第二套硬藏面板);📁 去文字变纯图标按钮,钉在 ⋯ 右边最右;跨断点实时切换。
18
+ - **顶栏自适应溢出 + 项目选择器 + 定时任务工具** —— 顶栏按实测宽度自动把放不下的入口收进「⋯」菜单(窗口变宽自动回来);顶栏直选打开项目;定时任务可配 AI 工具。
19
+ - **文件管理:压缩解压与文件夹上传**(#190)—— 文件树新增压缩 / 解压缩动作,支持整个文件夹上传(含冲突策略与大小限制提示)。
20
+ - **底栏主机资源监控** —— 底栏实时显示主机处理器与内存使用率,悬浮看明细。
21
+
22
+ ### Changed
23
+
24
+ - **设置面板 macOS 分组风视觉重构 + 内容区对齐精修**。
25
+ - **左栏操作区布局溢出修复 + 精简界面入口**。
26
+ - **布局页按界面顺序分组** —— 顶栏溢出菜单保序保样式,布局偏好里的分组与界面实际顺序一致。
27
+
28
+ ### Fixed
29
+
30
+ - **发送失败给出可见错误提示** —— 发送失败不再静默吞掉,界面上直接提示。
31
+ - **排队消息按索引删除**(#200)—— `removeQueued` 按索引删,文本只做回退匹配,重复文本不再连带误删。
32
+ - **更新面板:过时行按钮优先 + git 扩展名填充**(#202)。
33
+ - **↑ 翻历史可靠进入 prompt 历史**;**提交后按时间戳水位丢弃过期草稿**;**switchSession 限定 sessions 根目录**;**折叠控制展开时保持在左侧**。
34
+ - **在资源管理器中显示 / 默认打开不再压住 GUI 窗口**;**git 扩展更新命令加 `git:` 前缀,更新面板隐藏 SHA 并修复横向滚动**。
35
+ - **Windows ConPTY 关停死锁改走外部看门狗**(#215);**心跳定时器 unref,不再阻塞进程退出**。
36
+ - **无挂载 widget 时跳过刷新**(perf);**未知消息类型节流打日志**;**WS maxPayload 对齐 100MB 上限**。
37
+ - **安全**:TLS 下 `pi_web_token` cookie 加 `Secure` 标记;`shell.openExternal` 前做 URL scheme 白名单校验。
38
+ - **设置重载失败打日志**,不再静默吞错。
39
+
40
+ <!-- auto-i18n:start -->
41
+ ### i18n
42
+
43
+ - 前端新增 key(27):`brandLogo`、`brandName`、`manageProjects`、`projectPickerTitle`、`newProject`、`projectName`、`createAndOpenProject`、`invalidProjectName`、`openProject`、`fileCompress`、`fileExtract`、`fileCompressDownload`、`fileUploadFolder`、`fileChooseFolder`、`fileExtractDestination`、`fileConflictPolicy`、`fileConflictSkip`、`fileConflictOverwrite`、`fileConflictError`、`fileArchiveLimits`、`fileFolderUploadHint`、`fileTransferBusy`、`fileTransferFailed`、`conversationReadEnabledDesc`、`conversationReadOffHint`、`scheduleTaskEnabledDesc`、`scheduleTaskOffHint`
44
+ - 服务端新增 key(9):`sched.not.wired`、`sched.task.bad.schedule`、`sched.task.interval.too.short`、`sched.task.empty.prompt`、`sched.task.no.cwd`、`sched.list.empty`、`sched.cancel.empty.id`、`sched.cancel.not.found`、`sched.cancel.ok`
45
+ <!-- auto-i18n:end -->
46
+
11
47
  ## [0.89.0] — 2026-09-17
12
48
 
13
49
  ### Added
@@ -984,7 +1020,9 @@ when?, children?}`,也收 `topbar` / `settings` 这类简写别名);宿主
984
1020
  - 0.35.1(2026-08-27):编辑重问保留附件(#18)+ 全窗口拖放(#19)。
985
1021
  - 0.29.0(2026-08-23):全局搜索弹窗(Ctrl+K)+ 消息列表惰性窗口化。
986
1022
 
987
- [Unreleased]: https://github.com/xing-shuyin/pi-web-ui/compare/v0.88.0...main
1023
+ [Unreleased]: https://github.com/xing-shuyin/pi-web-ui/compare/v0.90.0...main
1024
+ [0.90.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.90.0
1025
+ [0.89.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.89.0
988
1026
  [0.88.0]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.88.0
989
1027
  [0.87.2]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.87.2
990
1028
  [0.87.1]: https://github.com/xing-shuyin/pi-web-ui/releases/tag/v0.87.1
@@ -26,7 +26,7 @@ import { Type } from "typebox";
26
26
  import { BgServerTracker } from "./bg-servers.js";
27
27
  import { checkAll as checkAllUpdates, collectTargets, compareVersions as compareSemver, resolveNpmRegistry, sortUpdateItems, } from "./update-check.js";
28
28
  import { hasActiveSubagentRun, hasPendingWaitSubscription, shouldRetainActive } from "./wait-subscription-scan.js";
29
- import { removeFirstOccurrence } from "./queue-utils.js";
29
+ import { removeQueuedByIndexOrText } from "./queue-utils.js";
30
30
  import { syncPluginToolsIntoSession } from "./plugins.js";
31
31
  import { SettingsService } from "./settings-service.js";
32
32
  import { GoalService } from "./goal-service.js";
@@ -46,6 +46,7 @@ import { makeEditSoftTool } from "./edit-soft-tool.js";
46
46
  import { collectSubagentDescendantIds, makeSubagentTools, subagentTitle, withSubagentOwner, } from "./subagents.js";
47
47
  import { makeDelegateTaskTool } from "./delegate-task.js";
48
48
  import { makeConversationReadTool, parseTranscriptLines, toTranscriptInput, } from "./conversation-read-tool.js";
49
+ import { makeScheduleTools } from "./schedule-agent-tool.js";
49
50
  import { buildAttachmentMessages, parseModelSpec } from "./attachments.js";
50
51
  import { buildVisionBridgePrompt, findVisionModels, transcribeImages } from "./vision-bridge.js";
51
52
  import { BUILTIN_SOUL, DEFAULT_PROMPT_TEMPLATE, buildToolsSchemaText, renderPromptTemplate, resolveSectionTexts, } from "./prompt-composer.js";
@@ -774,6 +775,15 @@ function collectSessionAnchors(filePath, q, cap = 10) {
774
775
  export function piSessionsRoot() {
775
776
  return process.env.PI_CODING_AGENT_SESSION_DIR || undefined;
776
777
  }
778
+ /** Guardrail: only transcripts under the shared sessions root
779
+ * (<agentDir>/sessions/) may be opened/deleted/renamed — never arbitrary files.
780
+ * Shared by deleteSession/renameSession/switchSession so the open path cannot
781
+ * escape the confinement the write paths already enforce. */
782
+ export function isInsideSessionsDir(agentDir, targetPath) {
783
+ const abs = resolve(targetPath);
784
+ const sessionsRoot = resolve(agentDir, "sessions");
785
+ return abs.startsWith(sessionsRoot + sep);
786
+ }
777
787
  export class ClientSession {
778
788
  clientId;
779
789
  /** Set by AgentService.attach: reflects the SERVICE-wide quiesce flag
@@ -846,6 +856,8 @@ export class ClientSession {
846
856
  onConversationChanged = undefined;
847
857
  /** index.ts 注入:读取插件当前注册的 AI 工具(attach 时拷贝到每个新会话)。 */
848
858
  pluginToolsProvider = undefined;
859
+ /** index.ts 经 AgentService 注入:内置调度存储(定时任务 Agent 工具用;未注入时工具直接报错)。 */
860
+ schedulerStore = undefined;
849
861
  /** index.ts 注入:读取插件当前注册的斜杠命令(目录展示 + prompt 拦截执行)。 */
850
862
  pluginCommandsProvider = undefined;
851
863
  /** index.ts 注入:读取插件注册的常驻后台任务(并入 bg_servers 面板)。 */
@@ -1332,6 +1344,14 @@ export class ClientSession {
1332
1344
  return !!t && t.enabled;
1333
1345
  },
1334
1346
  };
1347
+ /** schedule_* 工具的数据宿主:全局调度存储+创建时刻 live 的 cwd/活动对话。 */
1348
+ scheduleToolHost() {
1349
+ return {
1350
+ store: () => this.schedulerStore,
1351
+ cwd: () => this.cwd,
1352
+ activeConversationId: () => this.activeId,
1353
+ };
1354
+ }
1335
1355
  /** conversation_read 工具的数据宿主:读本客户端的 conversation 体系 +
1336
1356
  * 落盘会话目录。运行中对话按 id(实时消息,含未落盘的);历史按 path,
1337
1357
  * 且必须是会话列表里的路径(任意文件不给读)。跨标签页的实时运行不在
@@ -1826,6 +1846,11 @@ export class ClientSession {
1826
1846
  // 会话同样注册了它,可自然嵌套读取。不需要 ownerId——读的是本
1827
1847
  // 客户端的 conversation 体系与落盘历史,与派发者无关。
1828
1848
  makeConversationReadTool(this.conversationReadHost(), () => this.getLang()),
1849
+ // 定时唤醒三件套(schedule_task/list/cancel,issue #193):默认绑定
1850
+ // 发起对话(ownerId,无则活动对话),到期 steer 语义唤醒它;子代理
1851
+ // 会话同样注册(owner 即真正派发的父对话)。开关走统一工具 tab。
1852
+ // DSH 引擎无 customTool 注册面,不接。
1853
+ ...makeScheduleTools(this.scheduleToolHost(), ownerId, () => this.getLang()),
1829
1854
  ],
1830
1855
  });
1831
1856
  // 终端工具开关从创建起就生效(工具始终注册进注册表,只调活跃集)。
@@ -2035,12 +2060,13 @@ export class ClientSession {
2035
2060
  this.startWidgetsTimer();
2036
2061
  this.startStallTimer();
2037
2062
  }
2038
- /** Poll extension widgets so TUI-only overlays (e.g. rpiv-todo) stay live. */
2063
+ /** Poll extension widgets so TUI-only overlays (e.g. rpiv-todo) stay live.
2064
+ * Skips the refresh when no widgets are mounted — the common case. */
2039
2065
  startWidgetsTimer() {
2040
2066
  if (this.widgetsTimer)
2041
2067
  return;
2042
2068
  this.widgetsTimer = setInterval(() => {
2043
- if (!this.disposed)
2069
+ if (!this.disposed && this.webUi.hasWidgets())
2044
2070
  this.webUi.refresh();
2045
2071
  }, WIDGET_REFRESH_MS);
2046
2072
  }
@@ -3795,7 +3821,15 @@ export class ClientSession {
3795
3821
  await this.pushSlashCommands();
3796
3822
  this.pushSettings();
3797
3823
  }
3798
- catch { }
3824
+ catch (err) {
3825
+ console.error(`[settings] marker reload failed (conv ${this.activeId}):`, err);
3826
+ this.emit({
3827
+ type: "notice",
3828
+ level: "error",
3829
+ text: `设置应用失败:${err.message}`,
3830
+ textEn: `Failed to apply settings: ${err.message}`,
3831
+ });
3832
+ }
3799
3833
  }
3800
3834
  }
3801
3835
  }
@@ -4023,6 +4057,8 @@ export class ClientSession {
4023
4057
  const conv = this.conv;
4024
4058
  // 输入框内容被消费(发送/斜杠执行)→ 清掉该会话存过的草稿(best-effort)。
4025
4059
  // 快捷短语发送(不碰输入框)同样清:客户端发送成功后会把当前草稿重存回来。
4060
+ // clear() 同时记录 clear 时间戳水位:清掉之后才 landing 的旧 draft_update
4061
+ // (防抖延迟 / 跨 tab 陈旧写,ts <= 水位)由 store 直接丢弃,不复活。
4026
4062
  try {
4027
4063
  this.drafts.clear(conv.session.sessionId);
4028
4064
  }
@@ -4289,13 +4325,18 @@ export class ClientSession {
4289
4325
  this.flushSnapshot();
4290
4326
  }
4291
4327
  /**
4292
- * Remove ONE queued prompt text (the ✕ on a pending bubble) so it is neither
4328
+ * Remove ONE queued prompt (the ✕ on a pending bubble) so it is neither
4293
4329
  * shown nor eventually delivered. The pi SDK has no per-item queue API, so we
4294
- * drain the SDK queue (clearQueue), drop the target text and re-queue the rest
4330
+ * drain the SDK queue (clearQueue), drop the target item and re-queue the rest
4295
4331
  * in their original order; the SDK re-emits queue_update which re-syncs
4296
4332
  * conv.queueSteering / conv.queueFollowUp.
4333
+ *
4334
+ * `index` identifies WHICH bubble was clicked (same duplicate text can be
4335
+ * queued twice — text alone drops the wrong one). It is checked against the
4336
+ * item still at that position; on any mismatch we fall back to first-occurrence
4337
+ * text match (old clients, or the queue shifted between click and handling).
4297
4338
  */
4298
- async removeQueued(kind, text) {
4339
+ async removeQueued(kind, text, index) {
4299
4340
  const conv = this.conv;
4300
4341
  // Always-defined display mirrors; also the provenance of bubble rendering.
4301
4342
  const local = kind === "steer" ? conv.queueSteering : conv.queueFollowUp;
@@ -4308,17 +4349,19 @@ export class ClientSession {
4308
4349
  if (!s) {
4309
4350
  // Runtime not bound yet (fresh conversation) — drop the display mirror;
4310
4351
  // a later queue_update reconciles any SDK-side state.
4311
- const i = local.indexOf(text);
4312
- if (i >= 0)
4313
- local.splice(i, 1);
4352
+ const next = removeQueuedByIndexOrText(local, text, index);
4353
+ if (next.length !== local.length) {
4354
+ local.splice(0, local.length, ...next);
4355
+ }
4314
4356
  this.flushSnapshot();
4315
4357
  return;
4316
4358
  }
4317
4359
  const { steering, followUp } = s.clearQueue();
4318
- // 只移除第一条匹配:气泡 ✕ 对应的是「一条」消息,重复文本不能连带删除
4319
- // (旧实现用值过滤会把所有同文本项一起删掉,与本地显示镜像不一致)。
4320
- const keptSteering = kind === "steer" ? removeFirstOccurrence(steering, text) : steering;
4321
- const keptFollowUp = kind === "followUp" ? removeFirstOccurrence(followUp, text) : followUp;
4360
+ // 气泡 ✕ 对应的是「第几个气泡」(index),不是「哪段文本」:同一文本排队两次时
4361
+ // 按文本只会删掉第一条,点第二个气泡却删掉第一个。用 index 定位,位置对不上
4362
+ // (队列在点击与执行之间变化)或旧客户端没发 index 时回落到第一处文本匹配。
4363
+ const keptSteering = kind === "steer" ? removeQueuedByIndexOrText(steering, text, index) : steering;
4364
+ const keptFollowUp = kind === "followUp" ? removeQueuedByIndexOrText(followUp, text, index) : followUp;
4322
4365
  // Re-queue the survivors in original order. Guard each call so a single
4323
4366
  // failure can't leave the queue half-drained silently.
4324
4367
  for (const t of keptSteering) {
@@ -4355,7 +4398,8 @@ export class ClientSession {
4355
4398
  /** 存指定会话的未发送草稿(`draft_update` 入口,经 DispatchSession.saveDraft)。
4356
4399
  * 按消息自带的 sessionId 落键(不按 active 会话:切会话时的「离开刷盘」
4357
4400
  * 晚于服务端的切换到达)。空白新会话的转录还没落盘,但 id 内存里已有。
4358
- * 存完不推快照:同页的草稿本来就是自己打的;恢复走全量快照的 draft 字段。 */
4401
+ * 存完不推快照:同页的草稿本来就是自己打的;恢复走全量快照的 draft 字段。
4402
+ * 陈旧写由 ComposerDraftsStore 的 clear 水位丢弃(ts <= clearTs 不复活)。 */
4359
4403
  saveDraft(sessionId, text, ts) {
4360
4404
  try {
4361
4405
  if (!sessionId)
@@ -5080,10 +5124,7 @@ export class ClientSession {
5080
5124
  async deleteSession(path) {
5081
5125
  try {
5082
5126
  const abs = resolve(path);
5083
- // Guardrail: only transcripts under the shared sessions root
5084
- // (<agentDir>/sessions/) may be deleted — never arbitrary files.
5085
- const sessionsRoot = resolve(this.agentDir, "sessions");
5086
- if (!abs.startsWith(sessionsRoot + sep)) {
5127
+ if (!isInsideSessionsDir(this.agentDir, abs)) {
5087
5128
  this.emit({
5088
5129
  type: "notice",
5089
5130
  level: "error",
@@ -5183,8 +5224,7 @@ export class ClientSession {
5183
5224
  if (!trimmed)
5184
5225
  return;
5185
5226
  const abs = resolve(path);
5186
- const sessionsRoot = resolve(this.agentDir, "sessions");
5187
- if (!abs.startsWith(sessionsRoot + sep)) {
5227
+ if (!isInsideSessionsDir(this.agentDir, abs)) {
5188
5228
  this.emit({
5189
5229
  type: "notice",
5190
5230
  level: "error",
@@ -5679,6 +5719,16 @@ export class ClientSession {
5679
5719
  let openedTerminals = null;
5680
5720
  try {
5681
5721
  const targetPath = resolve(path);
5722
+ if (!isInsideSessionsDir(this.agentDir, targetPath)) {
5723
+ this.emit({
5724
+ type: "notice",
5725
+ level: "error",
5726
+ text: "只能打开会话目录中的对话记录",
5727
+ textEn: "Only transcripts inside the session directory can be opened",
5728
+ });
5729
+ this.flushSnapshot();
5730
+ return;
5731
+ }
5682
5732
  // A session may already be open in the running-conversation map. Reuse it
5683
5733
  // instead of creating a second writer for the same JSONL transcript.
5684
5734
  for (const conv of this.convs.values()) {
@@ -6053,8 +6103,11 @@ export class ClientSession {
6053
6103
  async openDefaultEntry(path) {
6054
6104
  return this.files.openDefaultEntry(path);
6055
6105
  }
6056
- async makeDir(relPath) {
6057
- return this.files.makeDir(relPath);
6106
+ async makeDir(relPath, setAsCwd = false) {
6107
+ const created = await this.files.makeDir(relPath);
6108
+ if (created && setAsCwd) {
6109
+ await this.setCwd(created);
6110
+ }
6058
6111
  }
6059
6112
  async cycleModel() {
6060
6113
  try {
@@ -6490,6 +6543,8 @@ export class AgentService {
6490
6543
  pluginBgTasksProvider = undefined;
6491
6544
  /** index.ts 注入:停止插件任务(kill_background_server with taskId)。 */
6492
6545
  pluginStopBgTask = undefined;
6546
+ /** index.ts 注入:内置调度存储(attach 时拷贝到每个新会话,供 schedule_* 工具)。 */
6547
+ schedulerStore = undefined;
6493
6548
  clients = new Map();
6494
6549
  /** Quiesce (draining) state — the service refuses NEW work (prompts, forks,
6495
6550
  * session resumes, new clients) so a deploy/upgrade/backup can stop cleanly
@@ -6583,6 +6638,33 @@ export class AgentService {
6583
6638
  }
6584
6639
  return undefined;
6585
6640
  }
6641
+ /** issue #193:定时任务唤醒发起对话。逐个客户端找持有方,用 steer 语义投递
6642
+ * (运行时插队、未跑时普通投递,不切用户当前对话);都找不到回 ok:false,
6643
+ * 调用方(index.ts executor)回落无头执行。quiesced 时直接拒绝。 */
6644
+ async wakeConversation(id, text) {
6645
+ if (!id || !text.trim())
6646
+ return { ok: false, error: "唤醒目标或文本为空" };
6647
+ if (this.quiesced)
6648
+ return { ok: false, error: "服务器正忙(quiesced),请稍后重试" };
6649
+ for (const cs of this.clients.values()) {
6650
+ try {
6651
+ const r = await cs.steerOwnConversation(id, text);
6652
+ if (r) {
6653
+ try {
6654
+ cs.flushSnapshot();
6655
+ }
6656
+ catch {
6657
+ // 推送失败不影响已投递的唤醒
6658
+ }
6659
+ return { ok: true, conversationId: id };
6660
+ }
6661
+ }
6662
+ catch {
6663
+ // 单客户端坏了继续找下一个
6664
+ }
6665
+ }
6666
+ return { ok: false, error: "目标对话不在运行中(已关闭或服务重启过)" };
6667
+ }
6586
6668
  /** issue #145:别处在某 cwd 下正在跑的对话(同项目并行感知用,不含请求方)。 */
6587
6669
  listProjectRunners(cwd, excludeClientId) {
6588
6670
  const out = [];
@@ -6872,6 +6954,7 @@ export class AgentService {
6872
6954
  cs.notifyExternalClients = (msg) => this.notifyClientsExcept(clientId, msg);
6873
6955
  cs.onRunningChanged = () => this.pokeExternalRunning(clientId);
6874
6956
  cs.steerConversationElsewhere = (id, text) => this.steerElsewhere(clientId, id, text);
6957
+ cs.schedulerStore = this.schedulerStore;
6875
6958
  // Make sure the restored/default workspace appears in the project list.
6876
6959
  this.stateStore.remember(clientId, cwd);
6877
6960
  if (cwd !== this.cwd) {
@@ -0,0 +1,23 @@
1
+ /** True when the browser connection is TLS: direct (`socket.encrypted`,
2
+ * express `req.secure`) or via a TLS-terminating proxy (`x-forwarded-proto`
3
+ * / RFC 7239 `forwarded`). */
4
+ export function isTlsRequest(req) {
5
+ if (req.socket?.encrypted)
6
+ return true;
7
+ if (req.secure === true)
8
+ return true;
9
+ const proto = req.headers?.["x-forwarded-proto"];
10
+ const first = Array.isArray(proto) ? proto[0] : proto;
11
+ if (typeof first === "string" && first.split(",")[0]?.trim().toLowerCase() === "https")
12
+ return true;
13
+ const fwd = req.headers?.forwarded;
14
+ const fwdFirst = Array.isArray(fwd) ? fwd[0] : fwd;
15
+ if (typeof fwdFirst === "string" && /(?:^|[;,]\s*)proto=https(?:[;,]|$)/i.test(fwdFirst))
16
+ return true;
17
+ return false;
18
+ }
19
+ /** Build the `Set-Cookie` value for `pi_web_token`. `encodedValue` is already
20
+ * `encodeURIComponent`'d (or `""` when clearing). */
21
+ export function buildPiWebTokenCookie(encodedValue, maxAge, secure) {
22
+ return `pi_web_token=${encodedValue}; Path=/; HttpOnly; SameSite=Strict; Max-Age=${maxAge}${secure ? "; Secure" : ""}`;
23
+ }
@@ -71,11 +71,24 @@ export function normalizeUiLayout(v) {
71
71
  const order = arr(o.order, 200);
72
72
  const groups = dict(o.groups, 200);
73
73
  const labels = dict(o.labels, 200);
74
+ // 用户对齐:只收 start/center/end(手改脏值回落丢弃,不污染合并结果)。
75
+ let align;
76
+ if (o.align && typeof o.align === "object" && !Array.isArray(o.align)) {
77
+ align = {};
78
+ for (const [k, val] of Object.entries(o.align).slice(0, 200)) {
79
+ if (k.length > 0 && k.length <= 96 && (val === "start" || val === "center" || val === "end")) {
80
+ align[k] = val;
81
+ }
82
+ }
83
+ if (Object.keys(align).length === 0)
84
+ align = undefined;
85
+ }
74
86
  return {
75
87
  ...(hidden ? { hidden } : {}),
76
88
  ...(shown ? { shown } : {}),
77
89
  ...(order ? { order } : {}),
78
90
  ...(groups ? { groups } : {}),
91
+ ...(align ? { align } : {}),
79
92
  ...(labels ? { labels } : {}),
80
93
  };
81
94
  }
@@ -41,6 +41,13 @@ function isValidDraft(d) {
41
41
  const o = d;
42
42
  return typeof o.text === "string" && typeof o.ts === "number" && typeof o.updatedAt === "number";
43
43
  }
44
+ /** clear 水位:sessionId → clear 时刻(max(旧条目 ts, Date.now()))。
45
+ * 模块级(非实例级):同进程每个 ClientSession 各有一个 ComposerDraftsStore
46
+ * 实例(agent-service.ts:1922),跨 tab 的 prompt-clear 与陈旧写落在不同
47
+ * 实例上,水位必须跨实例可见。进程重启即失 —— 重启后文件态本身已干净
48
+ * (clear 落盘删 key),late-save 无处可达。
49
+ * ponytail: 内存水位,TTL/持久化按需加(当前重启语义已够用)。 */
50
+ const clearedAt = new Map();
44
51
  export class ComposerDraftsStore {
45
52
  filePath;
46
53
  cache = null;
@@ -98,10 +105,16 @@ export class ComposerDraftsStore {
98
105
  return d ? { text: d.text, ts: d.ts } : undefined;
99
106
  }
100
107
  /** 存一条草稿:空文本 = 删除;同 key 上 ts 更大的才覆盖(last-write-wins,
101
- * `>=` 让同 ts 的重发幂等)。只有实际变化才写盘。 */
108
+ * `>=` 让同 ts 的重发幂等)。只有实际变化才写盘。
109
+ * clear 时间戳守卫:prompt() 清掉草稿后才 landing 的旧 `draft_update`
110
+ * (防抖延迟 / 跨 tab 陈旧写,ts <= clearTs)直接丢弃,不复活存储
111
+ * (reload-resurrect,见 clearedAt)。*/
102
112
  save(sessionId, text, ts) {
103
113
  if (!sessionId)
104
114
  return;
115
+ const cut = clearedAt.get(sessionId);
116
+ if (cut !== undefined && ts <= cut)
117
+ return;
105
118
  const map = this.load();
106
119
  const norm = normalizeDraftText(text);
107
120
  if (norm === undefined) {
@@ -119,11 +132,16 @@ export class ComposerDraftsStore {
119
132
  map[sessionId] = { text: norm, ts, updatedAt: Date.now() };
120
133
  this.persist();
121
134
  }
122
- /** 发送成功 / 会话删除后清掉(有 key 才写盘)。 */
135
+ /** 发送成功 / 会话删除后清掉(有 key 才写盘)。同时记录 clear 时间戳
136
+ * (max(旧条目 ts, Date.now())):之后 ts <= 该水位的 save 一律丢弃,
137
+ * 拦住 prompt() 清掉之后才 landing 的旧 `draft_update`。
138
+ * 模块级共享:同进程多 ClientSession(多 tab)共用同一水位。 */
123
139
  clear(sessionId) {
124
140
  if (!sessionId)
125
141
  return;
126
142
  const map = this.load();
143
+ const prevTs = map[sessionId]?.ts ?? 0;
144
+ clearedAt.set(sessionId, Math.max(prevTs, Date.now()));
127
145
  if (map[sessionId] !== undefined) {
128
146
  delete map[sessionId];
129
147
  this.persist();
@@ -39,6 +39,7 @@ import { TerminalManager, loadCommands, saveCommandsFile } from "../terminals.js
39
39
  import { saveUpload } from "../uploads.js";
40
40
  import { checkAll as checkAllUpdates, collectTargets, resolveNpmRegistry } from "../update-check.js";
41
41
  import { previewKind } from "../text-sniff.js";
42
+ import { removeQueuedByIndexOrText } from "../queue-utils.js";
42
43
  import { launchOrigin, toServiceInfo } from "../launch-origin.js";
43
44
  import { DshRuntime, loadDeepSeekKey } from "./dsh-client.js";
44
45
  import { DshStreamAccumulator, assistantMessageEventToUiMessage, toolResultEventToUiMessage, userMessageEventToUiMessage, } from "./dsh-serialize.js";
@@ -1535,17 +1536,19 @@ export class DshClientSession {
1535
1536
  await this.promptConv(conv, text, attachments, queue, sysPrefix);
1536
1537
  }
1537
1538
  /**
1538
- * Remove ONE queued prompt text (the ✕ on a pending bubble). DSH queues are
1539
+ * Remove ONE queued prompt (the ✕ on a pending bubble). DSH queues are
1539
1540
  * display-only — the prompt was already handed to the runtime inbox, so this
1540
1541
  * only drops the pending bubble from the UI (there is no per-item runtime
1541
- * cancel). Removes the first occurrence of `text`.
1542
+ * cancel). `index` is the clicked bubble's position (duplicate texts need
1543
+ * it); mismatch or omission falls back to first-occurrence text match.
1542
1544
  */
1543
- removeQueued(kind, text) {
1545
+ removeQueued(kind, text, index) {
1544
1546
  const conv = this.conv;
1545
1547
  const arr = kind === "steer" ? conv.queue.steering : conv.queue.followUp;
1546
- const i = arr.indexOf(text);
1547
- if (i >= 0)
1548
- arr.splice(i, 1);
1548
+ const next = removeQueuedByIndexOrText(arr, text, index);
1549
+ if (next.length !== arr.length) {
1550
+ arr.splice(0, arr.length, ...next);
1551
+ }
1549
1552
  this.flushSnapshot();
1550
1553
  }
1551
1554
  /** 向指定会话发提示(审查注入/重发用;不处理 fromDisk fork 与命名)。 */
@@ -2446,8 +2449,11 @@ export class DshClientSession {
2446
2449
  async completePath(input) {
2447
2450
  await this.files.completePath(input);
2448
2451
  }
2449
- async makeDir(input) {
2450
- await this.files.makeDir(input);
2452
+ async makeDir(input, setAsCwd = false) {
2453
+ const created = await this.files.makeDir(input);
2454
+ if (created && setAsCwd) {
2455
+ await this.setCwd(created);
2456
+ }
2451
2457
  }
2452
2458
  // -----------------------------------------------------------------------
2453
2459
  // 模型 / 思考