@steerable/agent-shell-web 0.14.3 → 0.14.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell-web",
3
- "version": "0.14.3",
3
+ "version": "0.14.4",
4
4
  "type": "module",
5
5
  "description": "Steerable framework — product-neutral renderer SPA source for @steerable/agent-shell (React + Vite). Consumed by product web entry points via the `@/` alias (anchored at this package's src/) and the createProductViteConfig factory. Published as a source package (src/), plus the compiled vite.base config factory (vite.base.js + .d.ts) for Node-side config loading.",
6
6
  "license": "Apache-2.0",
@@ -45,8 +45,8 @@
45
45
  "react-router-dom": "^6.30.0",
46
46
  "rehype-raw": "^7.0.0",
47
47
  "remark-gfm": "^4.0.1",
48
- "@steerable/agent-protocol": "0.14.3",
49
- "@steerable/agent-ui": "0.14.3"
48
+ "@steerable/agent-protocol": "0.14.4",
49
+ "@steerable/agent-ui": "0.14.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@tailwindcss/vite": "^4.3.0",
@@ -59,7 +59,7 @@
59
59
  "typescript": "^5.8.3",
60
60
  "vite": "^5.4.21",
61
61
  "vitest": "^3.2.4",
62
- "@steerable/pack-sdk": "0.14.3"
62
+ "@steerable/pack-sdk": "0.14.4"
63
63
  },
64
64
  "scripts": {
65
65
  "gen": "echo agent-shell-web",
@@ -14,6 +14,7 @@ import {
14
14
  import type { ChatMessage } from '@steerable/agent-protocol';
15
15
  import type { LocalChat, LocalChatAgent } from '@/lib/local-api';
16
16
  import { t } from '@/i18n';
17
+ import { CurrentMessageIdContext } from '@/lib/chat-mode-store';
17
18
  import { Markdown } from './Markdown';
18
19
  import { ExecutedActionsCard, type ExecutedAction } from './ExecutedActionsCard';
19
20
  import type { ChildInfo } from './OrchestrationChildrenCard';
@@ -550,6 +551,7 @@ export function AssistantMessage({
550
551
  continued ? <ContinuedHereLine>{card}</ContinuedHereLine> : card;
551
552
 
552
553
  return (
554
+ <CurrentMessageIdContext.Provider value={message.id}>
553
555
  <motion.div
554
556
  className="group/message"
555
557
  data-message-role="assistant"
@@ -560,8 +562,12 @@ export function AssistantMessage({
560
562
  >
561
563
  <div className="mx-auto w-full max-w-[var(--chat-input-box-width)] px-1">
562
564
  {(showTurnAgentBadges || isPlanMode) && (
563
- <div className="mb-1 flex min-h-4 items-center justify-between gap-2">
564
- {showTurnAgentBadges ? (
565
+ <div
566
+ className={`mb-1 flex min-h-4 items-center gap-2 ${
567
+ showTurnAgentBadges ? 'justify-between' : 'justify-start'
568
+ }`}
569
+ >
570
+ {showTurnAgentBadges && (
565
571
  <div
566
572
  data-testid="turn-agent-badges"
567
573
  className="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1"
@@ -575,13 +581,11 @@ export function AssistantMessage({
575
581
  />
576
582
  ))}
577
583
  </div>
578
- ) : (
579
- <div />
580
584
  )}
581
585
  {isPlanMode && (
582
586
  <span className="inline-flex items-center gap-1 rounded-full border border-amber-200 dark:border-amber-800/50 bg-amber-100/70 dark:bg-amber-900/30 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300 select-none">
583
- <LuListChecks className="h-3.5 w-3.5" />
584
- <span>{t('Plan mode (Plan)')}</span>
587
+ <LuListChecks className="h-3 w-3" />
588
+ <span>{t('Plan mode')}</span>
585
589
  </span>
586
590
  )}
587
591
  </div>
@@ -810,6 +814,7 @@ export function AssistantMessage({
810
814
  )}
811
815
  </div>
812
816
  </motion.div>
817
+ </CurrentMessageIdContext.Provider>
813
818
  );
814
819
  }
815
820
 
@@ -210,6 +210,13 @@ type MentionQuery = {
210
210
  // 里的工具卡片走同一份数据。
211
211
 
212
212
  type SlashSuggestion =
213
+ | {
214
+ kind: 'command';
215
+ insertToken: string;
216
+ label: string;
217
+ description: string;
218
+ targetMode: ChatMode;
219
+ }
213
220
  | { kind: 'skill'; insertToken: string; skill: SkillItem }
214
221
  | { kind: 'mcp'; insertToken: string; mcp: McpToolItem };
215
222
 
@@ -1165,6 +1172,37 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
1165
1172
  useEffect(() => {
1166
1173
  if (slashQuery) {
1167
1174
  const query = slashQuery.query;
1175
+ const modeCommandDefs: Array<{
1176
+ insertToken: string;
1177
+ label: string;
1178
+ description: string;
1179
+ targetMode: ChatMode;
1180
+ }> =
1181
+ onModeChange && getWebChatModes().includes('plan')
1182
+ ? [
1183
+ {
1184
+ insertToken: 'plan',
1185
+ label: t('Plan mode'),
1186
+ description: t('Switch to Plan mode or send a planning request'),
1187
+ targetMode: 'plan',
1188
+ },
1189
+ {
1190
+ insertToken: 'agent',
1191
+ label: t('Agent mode'),
1192
+ description: t('Switch back to Agent mode'),
1193
+ targetMode: 'agent',
1194
+ },
1195
+ ]
1196
+ : [];
1197
+ const commandMatches: SlashSuggestion[] = modeCommandDefs
1198
+ .filter(
1199
+ (cmd) =>
1200
+ cmd.insertToken.includes(query) ||
1201
+ cmd.label.toLowerCase().includes(query) ||
1202
+ cmd.description.toLowerCase().includes(query),
1203
+ )
1204
+ .map((cmd) => ({ kind: 'command' as const, ...cmd }));
1205
+
1168
1206
  const builtinCommandSkills: SkillItem[] = [
1169
1207
  {
1170
1208
  name: 'compact',
@@ -1196,23 +1234,28 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
1196
1234
  (t.description && t.description.toLowerCase().includes(query))
1197
1235
  )
1198
1236
  .map((t) => ({ kind: 'mcp' as const, insertToken: t.token, mcp: t }));
1199
- const combined = [...skillMatches, ...mcpMatches];
1237
+ const combined = [...commandMatches, ...skillMatches, ...mcpMatches];
1200
1238
  setSuggestions(combined);
1201
1239
  setShowSuggestions(combined.length > 0);
1202
1240
  setSelectedIndex(0);
1203
1241
  } else {
1204
1242
  setShowSuggestions(false);
1205
1243
  }
1206
- }, [slashQuery, skills, mcpTools]);
1244
+ }, [slashQuery, skills, mcpTools, onModeChange]);
1207
1245
 
1208
1246
  // 渲染行:分组标题 + 候选项(idx 对应扁平 suggestions 的下标,供高亮/键盘导航)
1209
1247
  const suggestionRows = useMemo(() => {
1210
1248
  const rows: Array<
1211
1249
  { type: 'header'; label: string } | { type: 'item'; item: SlashSuggestion; idx: number }
1212
1250
  > = [];
1251
+ const commandGroup = suggestions.filter((s) => s.kind === 'command');
1213
1252
  const skillGroup = suggestions.filter((s) => s.kind === 'skill');
1214
1253
  const mcpGroup = suggestions.filter((s) => s.kind === 'mcp');
1215
1254
  let idx = 0;
1255
+ if (commandGroup.length > 0) {
1256
+ rows.push({ type: 'header', label: t('Chat mode') });
1257
+ for (const c of commandGroup) rows.push({ type: 'item', item: c, idx: idx++ });
1258
+ }
1216
1259
  if (skillGroup.length > 0) {
1217
1260
  rows.push({ type: 'header', label: t('Run a local skill (Skill)') });
1218
1261
  for (const s of skillGroup) rows.push({ type: 'item', item: s, idx: idx++ });
@@ -1236,14 +1279,44 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
1236
1279
  }
1237
1280
  setAgentMenuOpen(false);
1238
1281
  };
1282
+ const handleKeyDown = (event: globalThis.KeyboardEvent) => {
1283
+ if (event.key === 'Escape') {
1284
+ event.stopPropagation();
1285
+ setAgentMenuOpen(false);
1286
+ }
1287
+ };
1239
1288
  window.addEventListener('pointerdown', handlePointerDown);
1240
- return () => window.removeEventListener('pointerdown', handlePointerDown);
1289
+ window.addEventListener('keydown', handleKeyDown);
1290
+ return () => {
1291
+ window.removeEventListener('pointerdown', handlePointerDown);
1292
+ window.removeEventListener('keydown', handleKeyDown);
1293
+ };
1241
1294
  }, [agentMenuOpen]);
1242
1295
 
1243
1296
  const handleSelectSuggestion = (suggestion: SlashSuggestion) => {
1297
+ const range = slashQuery ?? { start: 0, end: value.length };
1298
+ if (suggestion.kind === 'command') {
1299
+ onModeChange?.(suggestion.targetMode);
1300
+ const before = value.slice(0, range.start);
1301
+ const after = value.slice(range.end).replace(/^\s+/, '');
1302
+ const nextValue = `${before}${after}`;
1303
+ const caret = before.length;
1304
+ pendingCaretOffsetRef.current = caret;
1305
+ onChange(nextValue);
1306
+ setSlashQuery(null);
1307
+ setShowSuggestions(false);
1308
+ setTimeout(() => {
1309
+ const editor = editorRef.current;
1310
+ if (editor) {
1311
+ editor.focus();
1312
+ setCaretOffset(editor, Math.min(caret, getEditableText(editor).length));
1313
+ }
1314
+ }, 50);
1315
+ return;
1316
+ }
1317
+
1244
1318
  const token = `/${suggestion.insertToken} `;
1245
1319
  // 只替换光标处的 "/xxx" token,保留输入框里已有的其它内容。
1246
- const range = slashQuery ?? { start: 0, end: value.length };
1247
1320
  const nextValue = `${value.slice(0, range.start)}${token}${value.slice(range.end)}`;
1248
1321
  const caret = range.start + token.length;
1249
1322
  pendingCaretOffsetRef.current = caret;
@@ -1934,6 +2007,21 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
1934
2007
  }
1935
2008
  }
1936
2009
 
2010
+ if (
2011
+ event.key === 'Tab' &&
2012
+ event.shiftKey &&
2013
+ !event.metaKey &&
2014
+ !event.ctrlKey &&
2015
+ !event.altKey &&
2016
+ mode &&
2017
+ onModeChange &&
2018
+ getWebChatModes().length > 1
2019
+ ) {
2020
+ event.preventDefault();
2021
+ onModeChange(mode === 'plan' ? 'agent' : 'plan');
2022
+ return;
2023
+ }
2024
+
1937
2025
  // 空闲时 Enter / ⌘/Ctrl+Enter 发送,Shift+Enter 换行。
1938
2026
  // IME 候选确认的 Enter 已被上面的 composition 守卫拦截,不会误发送。
1939
2027
  const isSendCombo =
@@ -2069,21 +2157,25 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
2069
2157
  <div className="chat-input-container @container relative px-2.5 pb-2.5 pt-1">
2070
2158
  {(leadingChrome || selectedAgent || trailingChrome) && (
2071
2159
  <div
2072
- className="relative mb-1.5 flex min-w-0 items-end gap-1.5"
2160
+ className="relative mb-1 flex min-w-0 items-end gap-1 pl-0.5"
2073
2161
  data-testid="composer-meta-row"
2074
2162
  >
2075
- {leadingChrome}
2076
- {selectedAgent && (
2077
- <AgentSelect
2078
- refEl={agentMenuRef}
2079
- agent={selectedAgent}
2080
- agents={sortedAgents}
2081
- open={agentMenuOpen}
2082
- disabled={disabled || isStreaming || !onSelectAgent}
2083
- onOpenChange={setAgentMenuOpen}
2084
- onSelect={handleSelectAgent}
2085
- mentionReferences={mentionReferences}
2086
- />
2163
+ {(leadingChrome || selectedAgent) && (
2164
+ <div className="flex h-6 min-w-0 items-center gap-1">
2165
+ {leadingChrome}
2166
+ {selectedAgent && (
2167
+ <AgentSelect
2168
+ refEl={agentMenuRef}
2169
+ agent={selectedAgent}
2170
+ agents={sortedAgents}
2171
+ open={agentMenuOpen}
2172
+ disabled={disabled || isStreaming || !onSelectAgent}
2173
+ onOpenChange={setAgentMenuOpen}
2174
+ onSelect={handleSelectAgent}
2175
+ mentionReferences={mentionReferences}
2176
+ />
2177
+ )}
2178
+ </div>
2087
2179
  )}
2088
2180
  {trailingChrome && (
2089
2181
  <div className="ml-auto flex items-center min-w-0">
@@ -2115,6 +2207,7 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
2115
2207
  >
2116
2208
  {item.type === 'agent' ? (
2117
2209
  <span
2210
+ aria-hidden="true"
2118
2211
  className="mt-0.5 inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-[9px] font-semibold text-white"
2119
2212
  style={{ backgroundColor: item.color || '#7c3aed' }}
2120
2213
  >
@@ -2171,13 +2264,31 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
2171
2264
  : 'text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground'
2172
2265
  }`}
2173
2266
  >
2174
- {row.item.kind === 'skill' ? (
2267
+ {row.item.kind === 'command' ? (
2268
+ row.item.targetMode === 'plan' ? (
2269
+ <LuListChecks className="h-3.5 w-3.5 mt-0.5 shrink-0 text-amber-600 dark:text-amber-400" />
2270
+ ) : (
2271
+ <LuInfinity className="h-3.5 w-3.5 mt-0.5 shrink-0 text-agent-muted-foreground" />
2272
+ )
2273
+ ) : row.item.kind === 'skill' ? (
2175
2274
  <LuBlocks className="h-3.5 w-3.5 mt-0.5 shrink-0 text-agent-muted-foreground" />
2176
2275
  ) : (
2177
2276
  <LuPlug className="h-3.5 w-3.5 mt-0.5 shrink-0 text-agent-muted-foreground" />
2178
2277
  )}
2179
2278
  <div className="min-w-0 flex-1">
2180
- {row.item.kind === 'skill' ? (
2279
+ {row.item.kind === 'command' ? (
2280
+ <>
2281
+ <div className="text-xs font-medium truncate">
2282
+ {row.item.label}
2283
+ <span className="ml-1.5 text-[10px] font-normal text-agent-muted-foreground/70">
2284
+ /{row.item.insertToken}
2285
+ </span>
2286
+ </div>
2287
+ <div className="text-[10px] text-agent-muted-foreground/80 line-clamp-1">
2288
+ {row.item.description}
2289
+ </div>
2290
+ </>
2291
+ ) : row.item.kind === 'skill' ? (
2181
2292
  <>
2182
2293
  <div className="text-xs font-medium truncate">
2183
2294
  {row.item.skill.displayName ? (
@@ -2325,7 +2436,7 @@ export const ChatInput = forwardRef<ChatInputHandle, ChatInputProps>(
2325
2436
  {mode && onModeChange && getWebChatModes().length > 1 && (
2326
2437
  <ModeToggle
2327
2438
  mode={mode}
2328
- disabled={disabled || isStreaming}
2439
+ disabled={Boolean(disabled)}
2329
2440
  onChange={onModeChange}
2330
2441
  />
2331
2442
  )}
@@ -2472,17 +2583,17 @@ function ModeToggle({
2472
2583
  aria-checked={mode === 'agent'}
2473
2584
  disabled={disabled}
2474
2585
  onClick={() => onChange('agent')}
2475
- title={t('Agent mode: carry out the task directly')}
2586
+ title={t('Agent mode: carry out the task directly (Shift+Tab)')}
2476
2587
  data-testid="mode-agent"
2477
2588
  className={[
2478
2589
  'inline-flex h-5 items-center gap-1 rounded-full px-1.5 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
2479
2590
  mode === 'agent'
2480
- ? 'bg-agent-foreground/10 text-agent-foreground'
2591
+ ? 'bg-agent-foreground/10 text-agent-foreground font-medium'
2481
2592
  : 'text-agent-muted-foreground hover:text-agent-foreground',
2482
2593
  ].join(' ')}
2483
2594
  >
2484
2595
  <LuInfinity className="h-3 w-3" />
2485
- <span className="@max-sm:hidden">Agent</span>
2596
+ <span className="@max-sm:hidden">{t('Agent')}</span>
2486
2597
  </button>
2487
2598
  <button
2488
2599
  type="button"
@@ -2490,17 +2601,17 @@ function ModeToggle({
2490
2601
  aria-checked={mode === 'plan'}
2491
2602
  disabled={disabled}
2492
2603
  onClick={() => onChange('plan')}
2493
- title={t('Plan mode: make a plan first, read only and no execution')}
2604
+ title={t('Plan mode: explore read-only and make a plan first (Shift+Tab)')}
2494
2605
  data-testid="mode-plan"
2495
2606
  className={[
2496
2607
  'inline-flex h-5 items-center gap-1 rounded-full px-1.5 text-[12px] leading-[1.45] transition-colors disabled:cursor-not-allowed disabled:opacity-70',
2497
2608
  mode === 'plan'
2498
- ? 'bg-amber-400/20 text-amber-600 dark:text-amber-400'
2609
+ ? 'bg-amber-400/20 text-amber-700 dark:text-amber-300 font-medium'
2499
2610
  : 'text-agent-muted-foreground hover:text-agent-foreground',
2500
2611
  ].join(' ')}
2501
2612
  >
2502
2613
  <LuListChecks className="h-3 w-3" />
2503
- <span className="@max-sm:hidden">Plan</span>
2614
+ <span className="@max-sm:hidden">{t('Plan')}</span>
2504
2615
  </button>
2505
2616
  </div>
2506
2617
  );
@@ -2555,18 +2666,25 @@ function AgentSelect({
2555
2666
  type="button"
2556
2667
  onClick={() => onOpenChange(!open)}
2557
2668
  disabled={disabled}
2558
- className="inline-flex max-w-[140px] items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] text-agent-muted-foreground/80 transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:cursor-not-allowed disabled:opacity-70 @sm:max-w-[220px]"
2669
+ className="inline-flex h-6 max-w-[140px] items-center gap-1.5 rounded-full px-2 text-[11px] leading-none text-agent-muted-foreground/85 transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:cursor-not-allowed disabled:opacity-70 @sm:max-w-[220px]"
2559
2670
  title={buttonTitle}
2560
2671
  aria-haspopup="menu"
2561
2672
  aria-expanded={open}
2562
2673
  data-testid="agent-select"
2563
2674
  >
2564
- <AgentDot agent={agent} />
2675
+ <span
2676
+ aria-hidden="true"
2677
+ data-testid="agent-color-dot"
2678
+ className="h-2 w-2 shrink-0 rounded-full"
2679
+ style={{ backgroundColor: agent.color || '#7c3aed' }}
2680
+ />
2565
2681
  <span className="truncate font-medium">
2566
2682
  {agentLabel(agent)}
2567
2683
  {mentionedAgentCount > 0 ? ` +${mentionedAgentCount}` : ''}
2568
2684
  </span>
2569
- <LuChevronDown className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
2685
+ <LuChevronDown
2686
+ className={`h-3 w-3 shrink-0 text-agent-muted-foreground transition-transform ${open ? 'rotate-180' : ''}`}
2687
+ />
2570
2688
  </button>
2571
2689
 
2572
2690
  {open && (
@@ -2648,7 +2766,8 @@ function AgentSelect({
2648
2766
  function AgentDot({ agent }: { agent: LocalChatAgent }) {
2649
2767
  return (
2650
2768
  <span
2651
- className="inline-flex shrink-0 items-center justify-center rounded-full text-[9px] font-semibold text-white"
2769
+ aria-hidden="true"
2770
+ className="mt-0.5 inline-flex shrink-0 items-center justify-center rounded-full text-[9px] font-semibold text-white"
2652
2771
  style={{
2653
2772
  width: 14,
2654
2773
  height: 14,
@@ -1,4 +1,11 @@
1
- import { useState, type ReactNode } from 'react';
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useRef,
5
+ useState,
6
+ type ReactNode,
7
+ type RefObject,
8
+ } from 'react';
2
9
  import {
3
10
  LuCheck,
4
11
  LuChevronDown,
@@ -24,19 +31,49 @@ import { t } from '@/i18n';
24
31
  * 与专家选择器并排(项目在前)。
25
32
  *
26
33
  * 两个导出组件共用同一套按钮 + 上开菜单视觉:
27
- * - ChatProjectBadge — 会话内:显示当前项目(无项目时显示"选择项目"),
34
+ * - ChatProjectBadge — 会话内:显示当前项目(无项目时弱化为文件夹加号图标按钮),
28
35
  * 可关联/移动到其他项目、修改项目目录、移出项目。
29
36
  * - ProjectPickerButton — 落地页(还没有 chat):受控选择器,选中的
30
37
  * projectId 在首次发消息建会话时一并传入。
31
38
  *
32
- * 菜单用透明全屏 backdrop 关外击(一次性菜单,比 click-outside 管线简单)。
39
+ * 菜单用 pointerdown 外击与 Escape 关闭,不铺全屏遮罩,避免吞掉相邻控件的首次点击。
33
40
  */
34
41
 
35
42
  /* ---------------- 共享内部件 ---------------- */
36
43
 
44
+ function useMenuDismiss(
45
+ rootRef: RefObject<HTMLElement | null>,
46
+ open: boolean,
47
+ onClose: () => void,
48
+ ) {
49
+ useEffect(() => {
50
+ if (!open) return;
51
+ const handlePointerDown = (event: PointerEvent) => {
52
+ const target = event.target;
53
+ if (target instanceof Node && rootRef.current?.contains(target)) {
54
+ return;
55
+ }
56
+ onClose();
57
+ };
58
+ const handleKeyDown = (event: KeyboardEvent) => {
59
+ if (event.key === 'Escape') {
60
+ event.stopPropagation();
61
+ onClose();
62
+ }
63
+ };
64
+ window.addEventListener('pointerdown', handlePointerDown);
65
+ window.addEventListener('keydown', handleKeyDown);
66
+ return () => {
67
+ window.removeEventListener('pointerdown', handlePointerDown);
68
+ window.removeEventListener('keydown', handleKeyDown);
69
+ };
70
+ }, [rootRef, open, onClose]);
71
+ }
72
+
37
73
  function BadgeButton({
38
74
  label,
39
75
  active,
76
+ compact = false,
40
77
  open,
41
78
  busy,
42
79
  onClick,
@@ -45,18 +82,45 @@ function BadgeButton({
45
82
  label: string;
46
83
  /** true = 已关联/已选中项目(实心图标);false = 未选择(轻态无边框 + Plus 图标)。 */
47
84
  active: boolean;
85
+ /** true = 会话内未关联项目时仅渲染紧凑图标,避免常驻「选择项目」文字噪音。 */
86
+ compact?: boolean;
48
87
  open: boolean;
49
88
  busy: boolean;
50
89
  onClick: () => void;
51
90
  title?: string;
52
91
  }) {
92
+ if (compact) {
93
+ return (
94
+ <button
95
+ type="button"
96
+ onClick={onClick}
97
+ disabled={busy}
98
+ title={title}
99
+ aria-label={label}
100
+ aria-haspopup="menu"
101
+ aria-expanded={open}
102
+ data-testid="project-badge-button"
103
+ className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-agent-muted-foreground/65 transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:opacity-60"
104
+ >
105
+ {busy ? (
106
+ <LuLoaderCircle className="h-3.5 w-3.5 shrink-0 animate-spin" />
107
+ ) : (
108
+ <LuFolderPlus className="h-3.5 w-3.5 shrink-0" />
109
+ )}
110
+ </button>
111
+ );
112
+ }
113
+
53
114
  return (
54
115
  <button
55
116
  type="button"
56
117
  onClick={onClick}
57
118
  disabled={busy}
58
119
  title={title}
59
- className={`inline-flex max-w-full items-center gap-1.5 rounded-full px-2 py-0.5 text-[11px] transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:opacity-60 ${
120
+ aria-haspopup="menu"
121
+ aria-expanded={open}
122
+ data-testid="project-badge-button"
123
+ className={`inline-flex h-6 max-w-full items-center gap-1.5 rounded-full px-2 text-[11px] leading-none transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:opacity-60 ${
60
124
  active
61
125
  ? 'text-agent-muted-foreground/85'
62
126
  : 'text-agent-muted-foreground/65'
@@ -78,22 +142,17 @@ function BadgeButton({
78
142
  }
79
143
 
80
144
  function MenuShell({
81
- onClose,
82
145
  children,
83
146
  }: {
84
- onClose: () => void;
85
147
  children: ReactNode;
86
148
  }) {
87
149
  return (
88
- <>
89
- <div className="fixed inset-0 z-40 cursor-default" onClick={onClose} />
90
- <div
91
- role="menu"
92
- className="absolute bottom-full left-0 z-50 mb-1 w-64 overflow-hidden rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
93
- >
94
- {children}
95
- </div>
96
- </>
150
+ <div
151
+ role="menu"
152
+ className="absolute bottom-full left-0 z-50 mb-1 w-64 overflow-hidden rounded-agent-md border border-agent-border bg-agent-canvas p-1 shadow-lg"
153
+ >
154
+ {children}
155
+ </div>
97
156
  );
98
157
  }
99
158
 
@@ -174,7 +233,7 @@ export function ChatProjectBadge({
174
233
  onChatProjectChanged,
175
234
  }: {
176
235
  chatId: string;
177
- /** 当前会话绑定的项目;null = 无项目会话(徽章变为"选择项目")。 */
236
+ /** 当前会话绑定的项目;null = 无项目会话(弱化为文件夹加号图标)。 */
178
237
  project: LocalProject | null;
179
238
  /** 全部项目(用于关联列表)。 */
180
239
  projects: LocalProject[];
@@ -187,6 +246,9 @@ export function ChatProjectBadge({
187
246
  const [createOpen, setCreateOpen] = useState(false);
188
247
  const [busy, setBusy] = useState(false);
189
248
  const [error, setError] = useState<string | null>(null);
249
+ const rootRef = useRef<HTMLDivElement>(null);
250
+ const closeMenu = useCallback(() => setOpen(false), []);
251
+ useMenuDismiss(rootRef, open, closeMenu);
190
252
 
191
253
  const openCreate = () => {
192
254
  setOpen(false);
@@ -229,10 +291,11 @@ export function ChatProjectBadge({
229
291
  });
230
292
 
231
293
  return (
232
- <div className="relative">
294
+ <div ref={rootRef} className="relative">
233
295
  <BadgeButton
234
296
  label={project ? project.name : t('Choose a project')}
235
297
  active={Boolean(project)}
298
+ compact={!project}
236
299
  open={open}
237
300
  busy={busy}
238
301
  onClick={() => {
@@ -249,7 +312,7 @@ export function ChatProjectBadge({
249
312
  />
250
313
 
251
314
  {open && (
252
- <MenuShell onClose={() => setOpen(false)}>
315
+ <MenuShell>
253
316
  {project ? (
254
317
  <>
255
318
  <MenuSectionLabel>{t('Current project')}</MenuSectionLabel>
@@ -368,6 +431,9 @@ export function ProjectPickerButton({
368
431
  }) {
369
432
  const [open, setOpen] = useState(false);
370
433
  const [createOpen, setCreateOpen] = useState(false);
434
+ const rootRef = useRef<HTMLDivElement>(null);
435
+ const closeMenu = useCallback(() => setOpen(false), []);
436
+ useMenuDismiss(rootRef, open, closeMenu);
371
437
  const selected = value ? (projects.find((p) => p.id === value) ?? null) : null;
372
438
 
373
439
  const openCreate = () => {
@@ -376,7 +442,7 @@ export function ProjectPickerButton({
376
442
  };
377
443
 
378
444
  return (
379
- <div className="relative">
445
+ <div ref={rootRef} className="relative">
380
446
  <BadgeButton
381
447
  label={selected ? selected.name : t('Choose a project')}
382
448
  active={Boolean(selected)}
@@ -393,7 +459,7 @@ export function ProjectPickerButton({
393
459
  />
394
460
 
395
461
  {open && (
396
- <MenuShell onClose={() => setOpen(false)}>
462
+ <MenuShell>
397
463
  <MenuSectionLabel onAdd={openCreate}>{t('Project for new chat')}</MenuSectionLabel>
398
464
  <button
399
465
  type="button"
@@ -35,6 +35,7 @@ import {
35
35
  saveChatAttachments,
36
36
  type AttachmentFile,
37
37
  } from '@/lib/attachments';
38
+ import { parseModeSlashCommand } from '@/lib/chat-mode-store';
38
39
 
39
40
  /**
40
41
  * LocalChatPanel — the product chat shell.
@@ -274,6 +275,18 @@ export function LocalChatPanel({
274
275
  let trimmed = inputValue.trim();
275
276
  if (!trimmed && files.length === 0) return;
276
277
 
278
+ const slashCmd = trimmed ? parseModeSlashCommand(trimmed) : null;
279
+ let effectiveMode = mode;
280
+ if (slashCmd) {
281
+ effectiveMode = slashCmd.targetMode;
282
+ onModeChange?.(slashCmd.targetMode);
283
+ if (!slashCmd.remainder && files.length === 0) {
284
+ setInputValue('');
285
+ return;
286
+ }
287
+ trimmed = slashCmd.remainder;
288
+ }
289
+
277
290
  // 把上传的文件持久化到会话空间:成功项用落盘路径(稳定、可被 agent
278
291
  // 读回),失败项若在 Electron 下有源路径则退回源路径;浏览器模式下没有
279
292
  // 任何可用路径的失败项会被剔除并上报,绝不把空路径写进正文。
@@ -313,7 +326,7 @@ export function LocalChatPanel({
313
326
  // persisted record reflects that an image was attached.
314
327
  const imageAttachments = collectImageAttachments(resolvedFiles);
315
328
  const metadata = {
316
- ...(mode === 'plan' ? { mode: 'plan' as const } : {}),
329
+ ...(effectiveMode === 'plan' ? { mode: 'plan' as const } : {}),
317
330
  ...(execPolicy === 'full' ? { execPolicy: 'full' as const } : {}),
318
331
  ...(selectedAgentId ? { agentId: selectedAgentId } : {}),
319
332
  ...(mentionedAgentIds.length > 0 ? { mentionedAgentIds } : {}),
@@ -345,7 +358,17 @@ export function LocalChatPanel({
345
358
  setFiles(submittedFiles);
346
359
  setMentionReferences(submittedMentions);
347
360
  }
348
- }, [inputValue, files, mentionReferences, onSubmit, mode, execPolicy, chatId, selectedAgentId]);
361
+ }, [
362
+ inputValue,
363
+ files,
364
+ mentionReferences,
365
+ onSubmit,
366
+ mode,
367
+ onModeChange,
368
+ execPolicy,
369
+ chatId,
370
+ selectedAgentId,
371
+ ]);
349
372
 
350
373
  const sessionTodos = useMemo(
351
374
  () =>