agent-loft 0.2.50 → 0.2.51

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.
@@ -1,4 +1,4 @@
1
- import { fill, h, icon, starsLoader } from "../lib/dom.js";
1
+ import { fill, h, icon, starsLoader, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { clockTime, liveDuration, serverNow, setServerTime, tidyFooter } from "../lib/time.js";
4
4
  import { copyText, patchMarkdown, renderMarkdown } from "../lib/markdown.js";
@@ -7,13 +7,14 @@ import { WS } from "../lib/ws.js";
7
7
  import { agentLabel, convTitle, renderSidebar } from "./sidebar.js";
8
8
  import { baseName, renderContext, renderTopbar, updateCtxVisibility, usableAgents } from "./topbar.js";
9
9
  import { insertCard, renderInteraction, upsertInteraction } from "./interaction.js";
10
- import { renderChips, setBusy } from "./composer.js";
10
+ import { renderChips, setBusy, updateSendBtn } from "./composer.js";
11
11
  import { renderScheduled } from "./schedule.js";
12
12
  import { changeCwd, doAction, forkConversation } from "./conv-actions.js";
13
13
  import { scheduleNav } from "./msg-nav.js";
14
14
  import { linkReplyFiles } from "./file-preview.js";
15
15
  import { setTodos } from "./todos.js";
16
16
  import { expertIcon, findExpert } from "./experts.js";
17
+ import { preloadCommands } from "./slash.js";
17
18
 
18
19
  // ---------- 打开会话 ----------
19
20
 
@@ -48,6 +49,7 @@ export function newDraft() {
48
49
  renderSidebar();
49
50
  scheduleNav();
50
51
  ui.input?.focus();
52
+ preloadCommands();
51
53
  }
52
54
 
53
55
  export function renderEmpty() {
@@ -109,6 +111,7 @@ export async function openConversation(key) {
109
111
  const token = ++S.loadToken;
110
112
  if (S.current && S.current !== key) WS.raw({ t: "unsub", key: S.current });
111
113
  S.current = key;
114
+ if (S.convs.has(key)) preloadCommands();
112
115
  S.items = [];
113
116
  S.turnAi = null;
114
117
  turnStartAt = null;
@@ -145,6 +148,7 @@ export async function openConversation(key) {
145
148
  // 侧栏分页:打开的可能是还没拉到的那条(通知、地址里带的),拿到了就补进侧栏
146
149
  const known = S.convs.has(key);
147
150
  S.convs.set(key, data.info);
151
+ preloadCommands();
148
152
  if (!known) renderSidebar();
149
153
  S.allowedAgents = data.allowedAgents;
150
154
  if (Number.isFinite(data.serverTime)) setServerTime(data.serverTime);
@@ -160,7 +164,7 @@ export async function openConversation(key) {
160
164
  bulk = true;
161
165
  try {
162
166
  for (const m of data.messages) {
163
- if (m.role === "user") addItem({ type: "user", text: m.text, files: m.attachments ?? [], origin: null });
167
+ if (m.role === "user") addItem({ type: "user", text: m.text, files: m.attachments ?? [], origin: null, anchor: m.anchor });
164
168
  else if (m.role === "question") addItem({ type: "ix", id: m.question.id, ix: historyQuestion(key, m) });
165
169
  else addItem({ type: "ai", steps: m.steps ?? [], committed: m.text, partial: "", done: true, footer: m.footer, at: m.ts, anchor: m.anchor, segment: m.segment });
166
170
  }
@@ -458,13 +462,52 @@ function clampLongUsers(items) {
458
462
  }
459
463
  }
460
464
 
461
- /** 排队中的消息下面:「排队中 · 打断并发送」;停止、会话切换后没发出去的:「没有发出」 */
465
+ async function editUserMessage(item, queued, button) {
466
+ const key = S.current;
467
+ if (!key || S.editingMessage || S.sending) return;
468
+ S.editingMessage = key;
469
+ button.disabled = true;
470
+ updateSendBtn();
471
+ try {
472
+ const result = await api(`/api/conversations/${encodeURIComponent(key)}/${queued ? "cancel-queued" : "rewind"}`, {
473
+ method: "POST",
474
+ body: { id: item.id, anchor: item.anchor, sessionId: S.convs.get(key)?.sessionId },
475
+ });
476
+ if (S.current !== key) return;
477
+ if (!queued && !result.queued) await openConversation(key);
478
+ if (S.current !== key) return;
479
+ for (const upload of S.uploads) if (upload.url) URL.revokeObjectURL(upload.url);
480
+ S.uploads = result.draft.uploads;
481
+ ui.input.value = result.draft.text;
482
+ renderChips();
483
+ ui.input.dispatchEvent(new Event("input", { bubbles: true }));
484
+ ui.input.focus();
485
+ if (result.draft.missing) toast("部分附件已被清理,请重新添加");
486
+ } catch (err) {
487
+ toast(err.message);
488
+ } finally {
489
+ S.editingMessage = null;
490
+ button.disabled = false;
491
+ updateSendBtn();
492
+ }
493
+ }
494
+
495
+ function editButton(item, queued = false) {
496
+ const label = queued ? "撤销并编辑" : "回退到此处";
497
+ return h("button", {
498
+ class: "icon-btn", title: label, "aria-label": label,
499
+ onclick: (e) => void editUserMessage(item, queued, e.currentTarget),
500
+ }, icon("undo"));
501
+ }
502
+
503
+ /** 排队中的消息可立即发送或撤销编辑;停止后没发出去的显示「没有发出」 */
462
504
  function queueNote(item, state) {
463
505
  if (state === "dropped") return h("div", { class: "queue-note dropped" }, "没有发出");
464
506
  return h(
465
507
  "div",
466
508
  { class: "queue-note" },
467
509
  h("span", { class: "shimmer" }, "排队中,等上一条回复完"),
510
+ editButton(item, true),
468
511
  h("button", { class: "queue-jump", title: "停掉正在进行的回复,马上处理这条", onclick: () => void doAction("jump", item.id) }, "打断并发送"),
469
512
  );
470
513
  }
@@ -491,9 +534,10 @@ function renderItem(item) {
491
534
  renderUserFiles(item.files),
492
535
  item.text ? (item.bubble = h("div", { class: "msg-user" }, origin ? h("span", { class: "origin" }, origin) : null, item.text)) : null,
493
536
  (item.queueEl = item.queued ? queueNote(item, "queued") : null),
494
- item.text
495
- ? h("div", { class: "user-actions" }, h("button", { class: "icon-btn", title: "复制", onclick: () => copyText(item.text) }, icon("copy")))
496
- : null,
537
+ h("div", { class: "user-actions" },
538
+ item.text ? h("button", { class: "icon-btn", title: "复制", onclick: () => copyText(item.text) }, icon("copy")) : null,
539
+ editButton(item),
540
+ ),
497
541
  );
498
542
  }
499
543
  case "ai":
@@ -642,6 +686,21 @@ export function applyEvent(env) {
642
686
  S.seq.set(env.key, env.seq);
643
687
  const ev = env.ev;
644
688
  switch (ev.type) {
689
+ case "user_anchor": {
690
+ const item = S.items.find((it) => it.type === "user" && it.id === ev.id);
691
+ if (item) item.anchor = ev.anchor;
692
+ return;
693
+ }
694
+ case "history_reset": {
695
+ if (S.editingMessage === env.key) return;
696
+ const uploads = S.uploads;
697
+ void openConversation(env.key).then(() => {
698
+ if (S.current !== env.key) return;
699
+ S.uploads = uploads;
700
+ renderChips();
701
+ });
702
+ return;
703
+ }
645
704
  case "user": {
646
705
  // 排队的消息:正在进行的那一轮照常在上面接着输出,这条等轮到它(queue 事件)再挂占位
647
706
  const queued = !!ev.queued;
@@ -669,6 +728,14 @@ export function applyEvent(env) {
669
728
  }
670
729
  case "queue": {
671
730
  const it = S.items.find((i) => i.type === "user" && i.id === ev.id);
731
+ if (it && ev.state === "removed") {
732
+ it.el.remove();
733
+ S.items = S.items.filter((item) => item !== it);
734
+ if (ui.pinEl === it.el) ui.pinEl = null;
735
+ scheduleNav();
736
+ afterLayout();
737
+ return;
738
+ }
672
739
  if (it) setQueueState(it, ev.state === "dropped" ? "dropped" : null);
673
740
  // 轮到它了(上一轮刚出结果):挂上「思考中」占位,用时从现在算。被当成提问的回答时那一轮还在跑,不用挂
674
741
  if (ev.state === "started" && (!S.turnAi || S.turnAi.done)) {
@@ -4,7 +4,8 @@ import { userScrolled } from "./messages.js";
4
4
 
5
5
  // ---------- 消息区右边的快速定位(像网页版 ChatGPT) ----------
6
6
  // 每条用户消息一道短横线,竖着排在滚动条旁边,正看到的那条高亮;平时淡淡的,滚动时清楚些。
7
- // 鼠标移上去展开成列表,显示每条消息的开头,点一下跳过去。用户消息少于 3 条时不显示;窄屏(手机)不显示。
7
+ // 鼠标移上去展开成列表,显示每条消息的开头,点一下跳过去。用户消息少于 3 条时不显示。
8
+ // 手机只在滚动和操作刻度时显示,停止后自动隐藏,点刻度直接跳转。
8
9
 
9
10
  const MIN_USERS = 3;
10
11
  let entries = [];
@@ -12,11 +13,18 @@ let activeIdx = -1;
12
13
  let scheduled = false;
13
14
  let scrollRaf = 0;
14
15
  let scrollingTimer = 0;
16
+ let builtFor = null;
15
17
 
16
18
  export function createNav() {
19
+ resetScrolling();
20
+ builtFor = null;
21
+ entries = [];
17
22
  ui.navTicks = h("div", { class: "msg-nav-ticks" });
18
23
  ui.navPanel = h("div", { class: "msg-nav-panel" });
19
- ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow }, ui.navTicks, ui.navPanel);
24
+ ui.nav = h("nav", { class: "msg-nav", hidden: true, "aria-label": "消息快速定位", onpointerenter: revealActiveRow, onpointerdown: markScrolling }, ui.navTicks, ui.navPanel);
25
+ ui.navTicks.addEventListener("scroll", () => {
26
+ if (ui.nav.classList.contains("scrolling")) markScrolling();
27
+ }, { passive: true });
20
28
  ui.messages.addEventListener("scroll", onScroll, { passive: true });
21
29
  return ui.nav;
22
30
  }
@@ -41,6 +49,8 @@ function snippet(item) {
41
49
  function build() {
42
50
  if (!ui.nav) return;
43
51
  const users = S.view ? [] : S.items.filter((it) => it.type === "user" && it.el?.isConnected);
52
+ if (builtFor !== S.current || users.length < MIN_USERS) resetScrolling();
53
+ builtFor = S.current;
44
54
  ui.nav.hidden = users.length < MIN_USERS;
45
55
  activeIdx = -1;
46
56
  if (ui.nav.hidden) {
@@ -73,11 +83,23 @@ function jump(item) {
73
83
  ui.messages.scrollTo({ top: Math.max(0, item.el.offsetTop - covered() - 12), behavior: "smooth" });
74
84
  }
75
85
 
76
- function onScroll() {
86
+ function resetScrolling() {
87
+ clearTimeout(scrollingTimer);
88
+ cancelAnimationFrame(scrollRaf);
89
+ scrollRaf = 0;
90
+ ui.nav?.classList.remove("scrolling");
91
+ }
92
+
93
+ function markScrolling() {
77
94
  if (!entries.length) return;
78
95
  ui.nav.classList.add("scrolling");
79
96
  clearTimeout(scrollingTimer);
80
97
  scrollingTimer = setTimeout(() => ui.nav.classList.remove("scrolling"), 1200);
98
+ }
99
+
100
+ function onScroll() {
101
+ if (!entries.length) return;
102
+ markScrolling();
81
103
  if (scrollRaf) return;
82
104
  scrollRaf = requestAnimationFrame(() => {
83
105
  scrollRaf = 0;
@@ -87,6 +109,7 @@ function onScroll() {
87
109
 
88
110
  /** 正看到的:顶部往下三分之一处以上、最后一条用户消息;已经滚到底就是最后一条 */
89
111
  function updateActive() {
112
+ if (!entries.length) return;
90
113
  const m = ui.messages;
91
114
  const line = m.scrollTop + covered() + m.clientHeight * 0.3;
92
115
  let idx = 0;
@@ -3,6 +3,7 @@ import { api } from "../lib/api.js";
3
3
  import { desktop, remoteTabs, S, ui } from "../state.js";
4
4
  import { baseName } from "./topbar.js";
5
5
  import { newDraft, openConversation } from "./messages.js";
6
+ import { convExpert, expertIcon } from "./experts.js";
6
7
  import { leaveRemote } from "./remote.js";
7
8
  import { reportShellState } from "../lib/shell.js";
8
9
 
@@ -227,6 +228,13 @@ export function agentLabel(id) {
227
228
  return S.agents.find((a) => a.id === id)?.label ?? id;
228
229
  }
229
230
 
231
+ /** 会话名后面的专家图标,鼠标悬停在会话行上时显示 */
232
+ function convExpertMark(c) {
233
+ if (!c) return null;
234
+ const expert = convExpert(c);
235
+ return h("span", { class: "expert-mark", title: `专家:${expert.name}` }, expertIcon(expert, "expert-mark-icon"));
236
+ }
237
+
230
238
  function agentShort(id) {
231
239
  return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id;
232
240
  }
@@ -304,15 +312,6 @@ function setProjectOrder(order) {
304
312
  let dirDrag = null;
305
313
  let sidebarStale = false;
306
314
 
307
- /** 「最近」「项目」分组标题:点击折叠 / 展开,hover 时显示箭头 */
308
- function groupHead(label, id, folded) {
309
- return h(
310
- "button",
311
- { class: `conv-group${folded ? " collapsed" : ""}`, title: folded ? "展开" : "折叠", onclick: () => toggleSide("folded", id) },
312
- label,
313
- h("span", { class: "chev", html: ICON.down }),
314
- );
315
- }
316
315
  function toggleSide(list, id) {
317
316
  const set = new Set(sideState[list]);
318
317
  set.has(id) ? set.delete(id) : set.add(id);
@@ -478,26 +477,20 @@ export function renderSidebar() {
478
477
  orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
479
478
  // 定时任务的专用对话
480
479
  c.taskId ? h("span", { class: "brand-icon lead task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
481
- // 自定义专家的对话:前面挂专家的头像(以前的是 emoji)
482
- (c.expert?.avatar || c.expert?.icon) && !c.expert.builtin
483
- ? h("span", { class: "brand-icon lead expert-mark", title: `专家:${c.expert.name}` }, c.expert.avatar ? h("img", { src: c.expert.avatar, alt: "" }) : c.expert.icon)
484
- : null,
485
480
  h("span", { class: "title" }, convTitle(c)),
481
+ convExpertMark(c),
486
482
  fold ? caret(fold.folded, fold.toggle) : null,
487
483
  status(fold?.folded ? fold.keys : [c.key]),
488
484
  );
489
485
 
490
- // ---- 最近:Web 会话 + 每个飞书机器人一行(点开它最近活跃的聊天),按活跃时间混排 ----
491
- // 分叉出来的对话挂在主对话下面,整棵树按里面最近活跃的那条排
492
- const recent = [];
493
- for (const node of forkForest(visible.filter((c) => c.channel !== "feishu"))) {
494
- recent.push({ at: node.at, el: renderForkNode(node, (c, orphan, fold) => convRow(c, "", `${agentLabel(c.agent)} · ${c.cwd}`, orphan, fold)) });
495
- }
486
+ const nodes = [];
487
+ // 飞书机器人独立显示在文件夹后面,点击打开它最近活跃的聊天
488
+ const botRows = [];
496
489
  for (const bot of S.bots) {
497
490
  const convs = visible.filter((c) => c.channel === "feishu" && c.channelId === bot.id);
498
491
  if (bot.enabled === false && convs.length === 0) continue;
499
492
  const latest = convs[0];
500
- recent.push({
493
+ botRows.push({
501
494
  at: latest?.activeAt ?? 0,
502
495
  el: h(
503
496
  "button",
@@ -509,23 +502,13 @@ export function renderSidebar() {
509
502
  },
510
503
  h("span", { class: "brand-icon lead", title: "飞书", html: ICON.feishu }),
511
504
  h("span", { class: "title" }, bot.name),
505
+ convExpertMark(latest),
512
506
  status(convs.map((c) => c.key)),
513
507
  ),
514
508
  });
515
509
  }
516
- recent.sort((a, b) => b.at - a.at);
517
- const recentFolded = sideState.folded.includes("@recent");
518
- const nodes = [groupHead("最近", "@recent", recentFolded)];
519
- if (!recentFolded) {
520
- const rs = pages.recent;
521
- const shown = loadedPrefix(rs, recent);
522
- if (shown.length === 0 && !rs.loading) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
523
- nodes.push(...shown.slice(0, rs.show).map((r) => r.el));
524
- const btn = moreButton(rs, shown.length, RECENT_LIMIT, (limit) => fetchPage(rs, { scope: "recent", limit: String(limit) }));
525
- if (btn) nodes.push(btn);
526
- }
527
510
 
528
- // ---- 项目:Web 会话按工作目录分组,目录按用户排的顺序(见 orderProjectDirs) ----
511
+ // ---- Web 会话直接按工作目录分组,目录按用户排的顺序(见 orderProjectDirs) ----
529
512
  const byDir = new Map();
530
513
  for (const c of visible.filter((c) => c.channel === "web")) {
531
514
  if (!byDir.has(c.cwd)) byDir.set(c.cwd, []);
@@ -542,11 +525,9 @@ export function renderSidebar() {
542
525
  // 目录行要全部显示:服务端给了每个目录最近的活跃时间,加上本地已有的(刚建的、刚变活跃的)
543
526
  const dirAt = new Map(pages.dirAt);
544
527
  for (const [dir, convs] of byDir) dirAt.set(dir, Math.max(dirAt.get(dir) ?? 0, convs[0].activeAt));
545
- const projFolded = sideState.folded.includes("@projects");
546
- if (dirAt.size) nodes.push(groupHead("项目", "@projects", projFolded));
547
528
  projDirsByActivity = [...dirAt.keys()].sort((a, b) => dirAt.get(b) - dirAt.get(a));
548
529
  projDirs = orderProjectDirs(projDirsByActivity);
549
- if (dirAt.size && !projFolded) {
530
+ if (dirAt.size) {
550
531
  const clearDrop = () => ui.convList.querySelectorAll(".drop-before, .drop-after").forEach((el) => el.classList.remove("drop-before", "drop-after"));
551
532
  const endDrag = () => {
552
533
  dirDrag = null;
@@ -640,6 +621,8 @@ export function renderSidebar() {
640
621
  if (btn) nodes.push(h("div", { class: "sub-more" }, btn));
641
622
  }
642
623
  }
624
+ nodes.push(...botRows.sort((a, b) => b.at - a.at).map((r) => r.el));
625
+ if (!nodes.length) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
643
626
  paintList(nodes, askKeys.size);
644
627
  }
645
628
 
@@ -652,8 +635,11 @@ function paintList(nodes, asks) {
652
635
  markClipped();
653
636
  if (!clipObserver) {
654
637
  clipObserver = new ResizeObserver(() => markClipped());
655
- clipObserver.observe(ui.convList);
656
638
  }
639
+ clipObserver.disconnect();
640
+ clipObserver.observe(ui.convList);
641
+ // hover 显示专家图标时,标题的可用宽度也会变化
642
+ for (const el of ui.convList.querySelectorAll(".conv-item .title")) clipObserver.observe(el);
657
643
  if (hovered) {
658
644
  requestAnimationFrame(() => {
659
645
  const el = ui.convList.querySelector(".conv-item:hover .title");
@@ -8,9 +8,10 @@ import { autosize, hideKeyboardForMenu, sendMessage, updateSendBtn } from "./com
8
8
  // ---------- 斜杠命令补全 ----------
9
9
  //
10
10
  // 输入框里只有「/xxx」(还没打空格)时弹出命令表,顺序就是设置 → 命令里排好的。
11
- // 列表按 agent + 会话目录缓存一分钟:Claude 的原生命令要起一次进程才问得到。
11
+ // 列表按 agent + 工作目录缓存:提前加载,过期后先用已有列表、后台刷新。
12
12
 
13
- export const slash = { open: false, shown: false, items: [], index: 0, cache: new Map(), token: 0 };
13
+ export const slash = { open: false, shown: false, items: [], index: 0, cache: new Map(), pending: new Map(), token: 0, contextKey: null };
14
+ let cacheEpoch = 0;
14
15
 
15
16
  export function commandUsage(c) {
16
17
  return `/${c.name}${c.args ? ` ${c.args}` : ""}`;
@@ -26,15 +27,62 @@ export function currentAgentId() {
26
27
  return c?.agent ?? S.draftAgent ?? usableAgents()[0]?.id ?? "claude";
27
28
  }
28
29
 
29
- async function loadCommands(agent) {
30
- const cacheKey = `${agent}|${S.current ?? ""}`;
31
- const hit = slash.cache.get(cacheKey);
32
- if (hit && Date.now() - hit.at < 60_000) return hit.list;
33
- const q = S.current ? `?key=${encodeURIComponent(S.current)}` : "";
34
- const data = await api(`/api/agents/${agent}/commands${q}`);
35
- const list = data.commands.filter((c) => !c.hidden);
36
- slash.cache.set(cacheKey, { at: Date.now(), list });
37
- return list;
30
+ function commandContext(agent = currentAgentId()) {
31
+ const conv = S.current ? S.convs.get(S.current) : null;
32
+ const cwd = conv?.cwd ?? S.draftCwd ?? S.workspaceRoot ?? "";
33
+ const query = new URLSearchParams({ channel: "web" });
34
+ if (conv) query.set("key", conv.key);
35
+ else if (cwd) query.set("cwd", cwd);
36
+ return { cacheKey: JSON.stringify([agent, cwd]), url: `/api/agents/${agent}/commands?${query}` };
37
+ }
38
+
39
+ function refreshCommands({ cacheKey, url }) {
40
+ const pending = slash.pending.get(cacheKey);
41
+ if (pending) return pending;
42
+ const epoch = cacheEpoch;
43
+ const request = api(url).then((data) => {
44
+ const list = data.commands.filter((c) => !c.hidden);
45
+ if (epoch === cacheEpoch) {
46
+ slash.cache.set(cacheKey, { at: Date.now(), list });
47
+ if (slash.open && ui.input?.isConnected && commandContext().cacheKey === cacheKey) void updateSlashMenu();
48
+ }
49
+ return list;
50
+ }).finally(() => {
51
+ if (slash.pending.get(cacheKey) === request) slash.pending.delete(cacheKey);
52
+ });
53
+ slash.pending.set(cacheKey, request);
54
+ return request;
55
+ }
56
+
57
+ function loadCommands(agent) {
58
+ const context = commandContext(agent);
59
+ const hit = slash.cache.get(context.cacheKey);
60
+ if (hit && Date.now() - hit.at < 60_000) return Promise.resolve(hit.list);
61
+ const request = refreshCommands(context);
62
+ if (hit) {
63
+ void request.catch(() => {});
64
+ return Promise.resolve(hit.list);
65
+ }
66
+ return request;
67
+ }
68
+
69
+ /** 后台预加载,不阻塞页面;输入 / 时复用同一份进行中的请求 */
70
+ export function preloadCommands() {
71
+ const agent = currentAgentId();
72
+ if (!usableAgents().some((a) => a.id === agent)) return;
73
+ void loadCommands(agent).catch(() => {});
74
+ if (slash.open && slash.contextKey !== commandContext(agent).cacheKey) {
75
+ closeSlashMenu();
76
+ void updateSlashMenu();
77
+ }
78
+ }
79
+
80
+ /** 换账号、修改命令设置时作废旧缓存和在途请求的结果 */
81
+ export function clearCommandCache() {
82
+ cacheEpoch++;
83
+ slash.cache.clear();
84
+ slash.pending.clear();
85
+ closeSlashMenu();
38
86
  }
39
87
 
40
88
  function slashQuery() {
@@ -60,6 +108,8 @@ export async function updateSlashMenu() {
60
108
  const q = slashQuery();
61
109
  if (q === null) return closeSlashMenu();
62
110
  const token = ++slash.token;
111
+ const contextKey = commandContext().cacheKey;
112
+ slash.contextKey = contextKey;
63
113
  if (!slash.open) renderSlashMenu(null);
64
114
  let list;
65
115
  try {
@@ -69,7 +119,7 @@ export async function updateSlashMenu() {
69
119
  return;
70
120
  }
71
121
  // 等待期间又打了字:以最新的那次为准
72
- if (token !== slash.token || slashQuery() === null) return;
122
+ if (token !== slash.token || slashQuery() === null || commandContext().cacheKey !== contextKey) return;
73
123
  const items = matchCommands(list, slashQuery());
74
124
  if (items.length === 0) return closeSlashMenu();
75
125
  slash.items = items;
@@ -133,6 +183,7 @@ export function closeSlashMenu() {
133
183
  slash.shown = false;
134
184
  slash.items = [];
135
185
  slash.index = 0;
186
+ slash.contextKey = null;
136
187
  slash.token++;
137
188
  if (ui.slashMenu) ui.slashMenu.hidden = true;
138
189
  }
@@ -133,13 +133,7 @@ function openExpertCard(anchor, key, pinned) {
133
133
  row("引擎", agentLabel(c.agent)),
134
134
  row("模型", [model ?? "默认", effort ? ` · ${effort}` : ""].join("")),
135
135
  row("能力", abilities),
136
- access === "web"
137
- ? null
138
- : row(
139
- "工作目录",
140
- h("span", { class: "ec-cwd", title: c.cwd }, c.cwd),
141
- h("button", { class: "ec-link", onclick: () => (closeMenu(), changeCwd()) }, "切换"),
142
- ),
136
+ access === "web" ? null : row("工作目录", h("span", { class: "ec-cwd", title: c.cwd }, c.cwd)),
143
137
  ),
144
138
  );
145
139
  placePopover(pop, anchor);
@@ -302,7 +296,7 @@ export function usableAgents() {
302
296
  return usable.length ? usable : enabled;
303
297
  }
304
298
 
305
- /** 新对话里选专家:内置的在前,再是自己的(新建、管理在「设置 → 专家」里) */
299
+ /** 新对话里选专家:统一列表,简介在悬停时显示(新建、管理在「设置 → 专家」里) */
306
300
  function pickExpertMenu(anchor) {
307
301
  if (ui.menu?.dataset.for === "expert") return closeMenu();
308
302
  const pop = showPopover(anchor, { align: "left" });
@@ -314,16 +308,10 @@ function pickExpertMenu(anchor) {
314
308
  "button",
315
309
  { class: `pop-item${e.id === S.draftExpert ? " on" : ""}`, title: e.description || "", onclick: () => (closeMenu(), switchAgent(e.id)) },
316
310
  expertIcon(e),
317
- h("span", { class: "grow" }, h("span", { class: "t" }, e.name), e.description ? h("span", { class: "s" }, e.description) : null),
311
+ h("span", { class: "grow" }, h("span", { class: "t" }, e.name)),
318
312
  e.id === S.draftExpert ? h("span", { class: "check" }, "✓") : null,
319
313
  );
320
- const builtin = choices.filter((e) => e.builtin);
321
- const own = choices.filter((e) => !e.builtin);
322
- fill(
323
- pop,
324
- builtin.map(item),
325
- own.length ? [h("div", { class: "sep" }), h("div", { class: "pop-head" }, "我的专家"), own.map(item)] : null,
326
- );
314
+ fill(pop, choices.map(item));
327
315
  placePopover(pop, anchor);
328
316
  }
329
317