@steerable/agent-shell-web 0.14.4 → 0.14.5

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.
@@ -6,7 +6,11 @@
6
6
 
7
7
  import { t } from '@/i18n';
8
8
  import { formatElapsedCompact } from './elapsed';
9
- import { deriveActionStatusInfo } from './executed-actions-model';
9
+ import {
10
+ deriveActionStatusInfo,
11
+ parseImageAction,
12
+ resolveActionCard,
13
+ } from './executed-actions-model';
10
14
  import {
11
15
  countProcessReasoning,
12
16
  countProcessTools,
@@ -141,6 +145,109 @@ export function processStatusLabel(input: {
141
145
  return parts.join(' · ');
142
146
  }
143
147
 
148
+ type HistoryStageCategory = 'skill' | 'edit' | 'explore' | 'run' | 'image' | 'web';
149
+
150
+ function classifyHistoryStageAction(raw: unknown): HistoryStageCategory | null {
151
+ if (!raw || typeof raw !== 'object') return null;
152
+ const candidate = raw as {
153
+ tool?: unknown;
154
+ arguments?: unknown;
155
+ result?: unknown;
156
+ view?: { card?: 'generic' | 'terminal' | 'diff' | 'search' | 'read' | 'web'; declared?: boolean };
157
+ };
158
+ if (typeof candidate.tool !== 'string') return null;
159
+ const tool = candidate.tool;
160
+ if (tool === 'load_skill' || tool === 'read_skill' || tool === 'activate_skill') {
161
+ return 'skill';
162
+ }
163
+ if (candidate.arguments && typeof candidate.arguments === 'object') {
164
+ const pathArg = (candidate.arguments as { path?: unknown; file_path?: unknown }).path
165
+ ?? (candidate.arguments as { file_path?: unknown }).file_path;
166
+ if (typeof pathArg === 'string' && /(?:^|[/\\])SKILL\.md$/i.test(pathArg)) {
167
+ return 'skill';
168
+ }
169
+ }
170
+ if (
171
+ tool === 'view_image' ||
172
+ tool === 'render_office_preview' ||
173
+ parseImageAction({ tool, arguments: candidate.arguments, result: candidate.result }) !== null
174
+ ) {
175
+ return 'image';
176
+ }
177
+ const info = deriveActionStatusInfo({
178
+ tool,
179
+ arguments: candidate.arguments,
180
+ result: candidate.result,
181
+ });
182
+ if (info.classifiedShell) {
183
+ if (
184
+ info.classifiedShell.kind === 'search' ||
185
+ info.classifiedShell.kind === 'list' ||
186
+ info.classifiedShell.kind === 'read'
187
+ ) {
188
+ return 'explore';
189
+ }
190
+ return 'run';
191
+ }
192
+ const card = resolveActionCard({ tool, view: candidate.view });
193
+ if (card === 'diff') return 'edit';
194
+ if (card === 'read' || card === 'search') return 'explore';
195
+ if (card === 'web') return 'web';
196
+ if (
197
+ card === 'terminal' ||
198
+ tool === 'run_code' ||
199
+ tool.includes('exec') ||
200
+ tool.includes('shell') ||
201
+ tool.includes('snippet')
202
+ ) {
203
+ return 'run';
204
+ }
205
+ return null;
206
+ }
207
+
208
+ function categoryLabel(category: HistoryStageCategory): string {
209
+ switch (category) {
210
+ case 'skill':
211
+ return t('used skills');
212
+ case 'edit':
213
+ return t('edited files');
214
+ case 'explore':
215
+ return t('explored files');
216
+ case 'run':
217
+ return t('ran commands');
218
+ case 'image':
219
+ return t('viewed images');
220
+ case 'web':
221
+ return t('searched the web');
222
+ }
223
+ }
224
+
225
+ function summarizeHistoryStageCategories(
226
+ process: ReadonlyArray<ProcessTimelineBlock<unknown>>,
227
+ ): string | null {
228
+ const counts = new Map<HistoryStageCategory, { count: number; order: number }>();
229
+ let order = 0;
230
+ for (const block of process) {
231
+ if (block.type !== 'tools') continue;
232
+ for (const raw of block.actions) {
233
+ const cat = classifyHistoryStageAction(raw);
234
+ if (!cat) continue;
235
+ const prev = counts.get(cat);
236
+ if (prev) {
237
+ prev.count += 1;
238
+ } else {
239
+ counts.set(cat, { count: 1, order: order++ });
240
+ }
241
+ }
242
+ }
243
+ if (counts.size === 0) return null;
244
+ const top = [...counts.entries()]
245
+ .sort((a, b) => b[1].count - a[1].count || a[1].order - b[1].order)
246
+ .slice(0, 2)
247
+ .map(([cat]) => categoryLabel(cat));
248
+ return top.join(t(', '));
249
+ }
250
+
144
251
  /**
145
252
  * Single-line summary for folded prior process steps so only the latest stage
146
253
  * (`thinking` / `output` / latest single tool) remains directly visible.
@@ -152,10 +259,13 @@ export function completedHistoryLabel(
152
259
  const tools = countProcessTools(process);
153
260
  const failedCount = options?.showFailedCount ? countFailedProcessTools(process) : 0;
154
261
  const steps = tools > 0 ? tools : countHistoryStages(process);
262
+ const stageSummary = steps >= 3 ? summarizeHistoryStageCategories(process) : null;
155
263
  const base =
156
264
  steps === 1
157
265
  ? t('Completed 1 step')
158
- : t('Completed {count} steps', { count: steps });
266
+ : stageSummary
267
+ ? t('Completed {count} steps · {summary}', { count: steps, summary: stageSummary })
268
+ : t('Completed {count} steps', { count: steps });
159
269
  return failedCount > 0 ? `${base} · ${t('{count} failed', { count: failedCount })}` : base;
160
270
  }
161
271
 
@@ -141,11 +141,59 @@ function actionsFromTimeline(blocks: TurnBlock[] | undefined): ExecutedAction[]
141
141
  return actions;
142
142
  }
143
143
 
144
+ export interface ResolveTurnTodosInput {
145
+ /** Assistant message IDs belonging to this `ConversationTurn` in chronological order. */
146
+ assistantMessageIds: readonly string[];
147
+ /** True when this turn is the newest turn in the conversation (eligible for live tail actions). */
148
+ isLatestTurn: boolean;
149
+ executedActionsByMessageId?: Record<string, ExecutedAction[]>;
150
+ timelineByMessageId?: Record<string, TurnBlock[]>;
151
+ currentTurnActions?: ExecutedAction[];
152
+ currentTurnTimeline?: TurnBlock[];
153
+ }
154
+
155
+ /**
156
+ * Extract the latest `todo_write` snapshot strictly within a single `ConversationTurn`.
157
+ * Never walks backwards into earlier turns so unfinished items from an older turn
158
+ * cannot leak onto a subsequent unrelated prompt.
159
+ */
160
+ export function resolveTurnTodos(input: ResolveTurnTodosInput): SessionTodo[] | null {
161
+ if (input.isLatestTurn) {
162
+ const live =
163
+ latestTodosFromActions(input.currentTurnActions) ??
164
+ latestTodosFromActions(actionsFromTimeline(input.currentTurnTimeline));
165
+ if (live) return live;
166
+ }
167
+
168
+ for (let i = input.assistantMessageIds.length - 1; i >= 0; i -= 1) {
169
+ const id = input.assistantMessageIds[i]!;
170
+ const turnScoped =
171
+ latestTodosFromActions(input.executedActionsByMessageId?.[id]) ??
172
+ latestTodosFromActions(actionsFromTimeline(input.timelineByMessageId?.[id]));
173
+ if (turnScoped) return turnScoped;
174
+ }
175
+ return null;
176
+ }
177
+
178
+ /**
179
+ * Sticky turn-strip visibility:
180
+ * - Only rendered on the latest conversation turn so historical turns stay compact;
181
+ * - Visible throughout streaming (including the brief moment after `n/n` completes);
182
+ * - Auto-hides once streaming finishes and all items are completed, while keeping
183
+ * an interrupted/incomplete strip collapsed beneath the prompt until resumed or superseded.
184
+ */
185
+ export function shouldShowTurnTodoStrip(
186
+ todos: SessionTodo[] | null | undefined,
187
+ options: { isLatestTurn: boolean; isTurnStreaming: boolean },
188
+ ): todos is SessionTodo[] {
189
+ if (!todos || todos.length === 0) return false;
190
+ if (!options.isLatestTurn) return false;
191
+ if (options.isTurnStreaming) return true;
192
+ return todos.some((todo) => todo.status !== 'completed');
193
+ }
194
+
144
195
  /**
145
- * Composer meta-row visibility: keep active or incomplete task lists visible,
146
- * and keep newly completed lists visible while the turn is still streaming;
147
- * once the turn settles (`!isStreaming`), hide an all-completed list so stale
148
- * finished checklists do not linger above the next prompt.
196
+ * Composer meta-row visibility (legacy helper retained for pure model tests).
149
197
  */
150
198
  export function shouldShowComposerTodos(
151
199
  todos: SessionTodo[] | null | undefined,
@@ -1,6 +1,6 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { Outlet, useParams } from 'react-router-dom';
3
- import { LuPanelLeftOpen } from 'react-icons/lu';
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
3
+ import { LuBlocks, LuPanelLeftOpen, LuSettings, LuSquarePen } from 'react-icons/lu';
4
4
  import { AgentSidebar } from '@/components/AgentSidebar';
5
5
  import { TerminalPanel } from '@/components/TerminalPanel';
6
6
  import { RightPanelTabBar } from '@/layouts/RightPanelTabBar';
@@ -24,7 +24,12 @@ import {
24
24
  useChatsAndAgents,
25
25
  type UseChatsAndAgentsResult,
26
26
  } from '@/hooks/useChatsAndAgents';
27
- import { hostToolChrome, sanitizeRightPanelKind, settingsChrome } from '@/lib/host-tools';
27
+ import {
28
+ hasGeneralSettingsChrome,
29
+ hostToolChrome,
30
+ sanitizeRightPanelKind,
31
+ settingsChrome,
32
+ } from '@/lib/host-tools';
28
33
  import { t } from '@/i18n';
29
34
  import { BRAND_NAME } from '@/brand';
30
35
  import { chatWindowTitle } from '@/lib/chat-row-keys';
@@ -36,6 +41,7 @@ import {
36
41
  followRightPanelTab,
37
42
  openRightPanelTab,
38
43
  parseRightPanelMap,
44
+ revealDeliverableRightPanelTab,
39
45
  revealRightPanelTab,
40
46
  serializeRightPanelMap,
41
47
  shouldMountRightPanelTab,
@@ -49,6 +55,7 @@ import {
49
55
  parseLegacyChatSlotTabId,
50
56
  subscribeChatSlotFollows,
51
57
  subscribeChatSlotRequests,
58
+ subscribeChatSlotReveals,
52
59
  type ChatSlotRequest,
53
60
  } from '@/layouts/request-chat-slot';
54
61
 
@@ -95,7 +102,7 @@ export type { RightPanelMap, RightPanelTabs };
95
102
  */
96
103
  const SIDEBAR_WIDTH_KEY = 'deeppath.agent.sidebarWidth';
97
104
  const SIDEBAR_COLLAPSED_KEY = 'deeppath.agent.sidebarCollapsed';
98
- const DEFAULT_SIDEBAR_WIDTH = 200;
105
+ const DEFAULT_SIDEBAR_WIDTH = 224;
99
106
  const MIN_SIDEBAR_WIDTH = 180;
100
107
  const MAX_SIDEBAR_WIDTH = 420;
101
108
 
@@ -141,12 +148,18 @@ export type AgentOutletContext = UseChatsAndAgentsResult & {
141
148
  rightPanel: RightPanelState;
142
149
  /** 当前会话已经打开且正在显示的标签,顺序与标签条一致。 */
143
150
  openPanelIds: readonly string[];
151
+ /** 右侧整栏收起或尚未打开时,当前会话后台待预览的标签数。 */
152
+ hiddenPanelCount: number;
153
+ /** 右侧整栏收起时待预览的激活标签标题。 */
154
+ hiddenPanelTitle: string | null;
144
155
  /** 标题栏开关:整栏收着或空着时打开。 */
145
156
  onOpenRightPanel: () => void;
146
157
  };
147
158
 
148
159
  function AgentLayoutContent() {
149
160
  const data = useChatsAndAgents();
161
+ const navigate = useNavigate();
162
+ const location = useLocation();
150
163
  const { chatId } = useParams<{ chatId?: string }>();
151
164
  const currentChatTitle = chatId
152
165
  ? data.chats.find((chat) => chat.id === chatId)?.title
@@ -406,6 +419,10 @@ function AgentLayoutContent() {
406
419
  const [rightPanelMap, setRightPanelMap] = useState<RightPanelMap>(() =>
407
420
  readRightPanelMap(),
408
421
  );
422
+ const [stagedTabsByChatId, setStagedTabsByChatId] = useState<
423
+ Record<string, RightPanelTabRecord>
424
+ >({});
425
+ const stagedTabRef = useRef<RightPanelTabRecord | null>(null);
409
426
 
410
427
  // 切换会话时重新读取映射(迁移老 key / 多窗口写入)。
411
428
  useEffect(() => {
@@ -413,10 +430,21 @@ function AgentLayoutContent() {
413
430
  }, [readRightPanelMap]);
414
431
 
415
432
  const panelEntry: RightPanelTabs | null = chatId ? rightPanelMap[chatId] ?? null : null;
433
+ const stagedTab: RightPanelTabRecord | null = chatId ? stagedTabsByChatId[chatId] ?? null : null;
434
+ stagedTabRef.current = stagedTab;
416
435
  const panelOpen = panelEntry !== null && panelEntry.collapsed !== true;
417
436
  const activePanelTab = panelOpen
418
437
  ? panelEntry.tabs.find((tab) => tab.id === panelEntry.activeTabId) ?? null
419
438
  : null;
439
+ const hiddenActiveTab = !panelOpen
440
+ ? (panelEntry?.tabs.find((tab) => tab.id === panelEntry.activeTabId)
441
+ ?? panelEntry?.tabs[0]
442
+ ?? stagedTab)
443
+ : null;
444
+ const hiddenPanelCount = !panelOpen
445
+ ? (panelEntry && panelEntry.tabs.length > 0 ? panelEntry.tabs.length : stagedTab ? 1 : 0)
446
+ : 0;
447
+ const hiddenPanelTitle = hiddenActiveTab?.title ?? null;
420
448
  const rightPanel: RightPanelState = activePanelTab?.kind ?? null;
421
449
  const openPanelIds = panelOpen
422
450
  ? [...new Set(panelEntry.tabs.map((tab) => tab.kind))]
@@ -511,11 +539,16 @@ function AgentLayoutContent() {
511
539
  applyPanelEntry(expandRightPanel(current));
512
540
  return;
513
541
  }
542
+ if (stagedTabRef.current) {
543
+ setInspectedTask(null);
544
+ applyPanelEntry(openRightPanelTab(null, stagedTabRef.current));
545
+ return;
546
+ }
514
547
  const first = packChatSlots[0]?.slotId ?? sanitizeRightPanelKind('terminal');
515
548
  if (!first) return;
516
549
  setInspectedTask(null);
517
550
  openPanelKind(first);
518
- }, [openPanelKind, packChatSlots]);
551
+ }, [applyPanelEntry, openPanelKind, packChatSlots]);
519
552
 
520
553
  const collapseRightSide = useCallback(() => {
521
554
  const current = panelEntryRef.current;
@@ -639,14 +672,43 @@ function AgentLayoutContent() {
639
672
  // 交付文件点击要打开对应栏位。菜单按钮不在文档里时也能切过去。
640
673
  useEffect(() => subscribeChatSlotRequests(openPanelTab), [openPanelTab]);
641
674
 
675
+ // 本会话活跃回合新产出主交付物时,自动展开右侧预览(若用户曾主动收起则保持收起并点亮角标)。
676
+ useEffect(() => subscribeChatSlotReveals((request) => {
677
+ const tab = tabForRequest(request);
678
+ if (!tab || tab.kind === 'terminal') return;
679
+ const current = panelEntryRef.current;
680
+ const next = revealDeliverableRightPanelTab(current, tab);
681
+ if (next === current) return;
682
+ if (!next.collapsed && current === null) setInspectedTask(null);
683
+ applyPanelEntry(next);
684
+ }), [applyPanelEntry, tabForRequest]);
685
+
642
686
  // 对话滚动或新产物换右侧正在看的文件。关着的栏不弹出,终端不被抢走。
643
687
  useEffect(() => subscribeChatSlotFollows((request) => {
644
688
  const tab = tabForRequest(request);
645
689
  if (!tab || tab.kind === 'terminal') return;
646
- const next = followRightPanelTab(panelEntryRef.current, tab);
647
- if (!next || next === panelEntryRef.current) return;
690
+ const current = panelEntryRef.current;
691
+ if (current === null) {
692
+ if (chatId) {
693
+ setStagedTabsByChatId((prev) => {
694
+ const existing = prev[chatId];
695
+ if (
696
+ existing
697
+ && existing.kind === tab.kind
698
+ && existing.contentId === tab.contentId
699
+ && existing.title === tab.title
700
+ ) {
701
+ return prev;
702
+ }
703
+ return { ...prev, [chatId]: tab };
704
+ });
705
+ }
706
+ return;
707
+ }
708
+ const next = followRightPanelTab(current, tab);
709
+ if (!next || next === current) return;
648
710
  applyPanelEntry(next);
649
- }), [applyPanelEntry, tabForRequest]);
711
+ }), [applyPanelEntry, chatId, tabForRequest]);
650
712
 
651
713
  // Same drag ergonomics as the sidebar handle, mirrored: the terminal's
652
714
  // right edge is pinned to the window's right padding (p-1.5 = 6px), so the
@@ -728,10 +790,56 @@ function AgentLayoutContent() {
728
790
  ? []
729
791
  : (activeApp?.hiddenNavItems ?? []);
730
792
 
793
+ const hiddenSet = useMemo(() => new Set(hiddenNavItems), [hiddenNavItems]);
794
+ const pluginsAvailable =
795
+ (!hiddenSet.has('agents') && settingsChrome('agents')) ||
796
+ (!hiddenSet.has('skills') && settingsChrome('skills')) ||
797
+ (!hiddenSet.has('mcp') && settingsChrome('mcp')) ||
798
+ (!(hiddenSet.has('agents') && hiddenSet.has('skills') && hiddenSet.has('mcp')) &&
799
+ settingsChrome('web-search'));
800
+ const onSettingsPage = location.pathname === '/settings';
801
+ const settingsSection = useMemo(
802
+ () => new URLSearchParams(location.search).get('section'),
803
+ [location.search],
804
+ );
805
+ const onPluginsSettings =
806
+ pluginsAvailable &&
807
+ onSettingsPage &&
808
+ (settingsSection === 'plugins' ||
809
+ settingsSection === 'agents' ||
810
+ settingsSection === 'skills' ||
811
+ settingsSection === 'mcp');
812
+ const onGeneralSettings = onSettingsPage && !onPluginsSettings;
813
+ const onNewChatHome = !chatId && !onSettingsPage;
814
+
815
+ // 收起侧边栏时 AgentSidebar 未挂载,由外层补接菜单 Cmd+N 及全局 Cmd/Ctrl+Shift+O。
816
+ useEffect(() => {
817
+ if (!sidebarCollapsed) return;
818
+ const bridge = getHostBridge();
819
+ if (!bridge?.onMenuNewChat) return;
820
+ bridge.onMenuNewChat(() => {
821
+ navigate('/agent');
822
+ });
823
+ return () => {
824
+ bridge.offMenuNewChat?.();
825
+ };
826
+ }, [sidebarCollapsed, navigate]);
827
+
828
+ useEffect(() => {
829
+ const onKeyDown = (event: KeyboardEvent) => {
830
+ if ((event.metaKey || event.ctrlKey) && event.shiftKey && !event.altKey && event.key.toLowerCase() === 'o') {
831
+ event.preventDefault();
832
+ navigate('/agent');
833
+ }
834
+ };
835
+ window.addEventListener('keydown', onKeyDown);
836
+ return () => window.removeEventListener('keydown', onKeyDown);
837
+ }, [navigate]);
838
+
731
839
  return (
732
840
  <div className="relative flex h-full w-full bg-agent-muted/30">
733
841
  {sidebarCollapsed ? (
734
- // 收起态:窄 rail 只放展开按钮。新建对话仍可用 Cmd+N / 菜单触发。
842
+ // 收起态:窄 rail 提供展开、新对话、插件与底部设置快捷入口。
735
843
  <div className="flex h-full w-10 flex-shrink-0 flex-col items-center border-r border-agent-border/60 bg-agent-muted/70 backdrop-blur-md">
736
844
  <div className="flex h-11 w-full items-center justify-center">
737
845
  <button
@@ -744,6 +852,59 @@ function AgentLayoutContent() {
744
852
  <LuPanelLeftOpen className="h-3.5 w-3.5" />
745
853
  </button>
746
854
  </div>
855
+ <div className="flex flex-col items-center gap-0.5 pb-1">
856
+ <button
857
+ type="button"
858
+ data-testid="sidebar-rail-new-chat"
859
+ onClick={() => navigate('/agent')}
860
+ className={[
861
+ 'flex h-7 w-7 items-center justify-center rounded-full transition-colors duration-200',
862
+ onNewChatHome
863
+ ? 'bg-agent-foreground/10 text-agent-foreground'
864
+ : 'text-agent-foreground/85 hover:bg-agent-foreground/5 hover:text-agent-foreground',
865
+ ].join(' ')}
866
+ title={t('Start a new chat')}
867
+ aria-label={t('Start a new chat')}
868
+ >
869
+ <LuSquarePen className="h-3.5 w-3.5" />
870
+ </button>
871
+ {pluginsAvailable && (
872
+ <button
873
+ type="button"
874
+ data-testid="sidebar-rail-plugins"
875
+ onClick={() => navigate('/settings?section=plugins')}
876
+ className={[
877
+ 'flex h-7 w-7 items-center justify-center rounded-full transition-colors duration-200',
878
+ onPluginsSettings
879
+ ? 'bg-agent-foreground/10 text-agent-foreground'
880
+ : 'text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground',
881
+ ].join(' ')}
882
+ title={t('Plugins')}
883
+ aria-label={t('Plugins')}
884
+ >
885
+ <LuBlocks className="h-3.5 w-3.5" />
886
+ </button>
887
+ )}
888
+ </div>
889
+ {hasGeneralSettingsChrome() && (
890
+ <div className="mt-auto flex w-full flex-col items-center border-t border-agent-border/40 py-1.5">
891
+ <button
892
+ type="button"
893
+ data-testid="sidebar-rail-settings"
894
+ onClick={() => navigate('/settings')}
895
+ className={[
896
+ 'flex h-7 w-7 items-center justify-center rounded-full transition-colors duration-200',
897
+ onGeneralSettings
898
+ ? 'bg-agent-foreground/10 text-agent-foreground'
899
+ : 'text-agent-muted-foreground hover:bg-agent-foreground/5 hover:text-agent-foreground',
900
+ ].join(' ')}
901
+ title={t('Settings')}
902
+ aria-label={t('Settings')}
903
+ >
904
+ <LuSettings className="h-3.5 w-3.5" />
905
+ </button>
906
+ </div>
907
+ )}
747
908
  </div>
748
909
  ) : (
749
910
  <>
@@ -792,6 +953,8 @@ function AgentLayoutContent() {
792
953
  chatSlots: packChatSlots,
793
954
  rightPanel,
794
955
  openPanelIds,
956
+ hiddenPanelCount,
957
+ hiddenPanelTitle,
795
958
  onOpenRightPanel: expandRightSide,
796
959
  } satisfies AgentOutletContext}
797
960
  />
@@ -1,4 +1,4 @@
1
- import { LuCopy } from 'react-icons/lu';
1
+ import { LuPanelRight, LuPanelRightClose } from 'react-icons/lu';
2
2
  import { t } from '@/i18n';
3
3
 
4
4
  /**
@@ -6,30 +6,48 @@ import { t } from '@/i18n';
6
6
  */
7
7
  export function PanelToggleButton({
8
8
  pressed,
9
+ hiddenTabCount = 0,
10
+ hiddenActiveTitle = null,
9
11
  onClick,
10
12
  }: {
11
13
  pressed: boolean;
14
+ hiddenTabCount?: number;
15
+ hiddenActiveTitle?: string | null;
12
16
  onClick: () => void;
13
17
  }) {
18
+ const showBadge = !pressed && hiddenTabCount > 0;
19
+ const title = pressed
20
+ ? t('Close {name}', { name: t('Panels') })
21
+ : showBadge && hiddenActiveTitle
22
+ ? t('Open preview ({title})', { title: hiddenActiveTitle })
23
+ : t('Open {name}', { name: t('Panels') });
24
+
14
25
  return (
15
26
  <button
16
27
  type="button"
17
28
  onClick={onClick}
18
- className={`flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-xs transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground ${
29
+ className={`relative flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-xs transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground ${
19
30
  pressed
20
31
  ? 'bg-agent-foreground/10 text-agent-foreground'
21
32
  : 'text-agent-muted-foreground'
22
33
  }`}
23
- title={
24
- pressed
25
- ? t('Close {name}', { name: t('Panels') })
26
- : t('Open {name}', { name: t('Panels') })
27
- }
28
- aria-label={t('Panels')}
34
+ title={title}
35
+ aria-label={showBadge && hiddenActiveTitle ? title : t('Panels')}
29
36
  aria-pressed={pressed}
30
37
  data-testid="header-chat-panels"
31
38
  >
32
- <LuCopy className="h-4 w-4" />
39
+ {pressed ? (
40
+ <LuPanelRightClose className="h-4 w-4" />
41
+ ) : (
42
+ <LuPanelRight className="h-4 w-4" />
43
+ )}
44
+ {showBadge && (
45
+ <span
46
+ className="pointer-events-none absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-agent-accent ring-2 ring-agent-canvas"
47
+ data-testid="header-chat-panels-badge"
48
+ aria-hidden="true"
49
+ />
50
+ )}
33
51
  </button>
34
52
  );
35
53
  }
@@ -9,6 +9,8 @@ export interface ConversationPreviewTarget {
9
9
  chatId: string;
10
10
  messageId: string;
11
11
  path: string;
12
+ /** True when this target is newly produced in the active turn and should auto-reveal the preview pane unless collapsed by user. */
13
+ autoReveal?: boolean;
12
14
  }
13
15
 
14
16
  const targets = new Map<string, ConversationPreviewTarget>();
@@ -22,6 +24,7 @@ function emit(target: ConversationPreviewTarget): void {
22
24
  previous
23
25
  && previous.messageId === target.messageId
24
26
  && previous.path === target.path
27
+ && !target.autoReveal
25
28
  ) {
26
29
  return;
27
30
  }
@@ -13,6 +13,7 @@ export interface ChatSlotRequest {
13
13
  }
14
14
 
15
15
  const listeners = new Set<(request: ChatSlotRequest) => void>();
16
+ const revealListeners = new Set<(request: ChatSlotRequest) => void>();
16
17
  const followListeners = new Set<(request: ChatSlotRequest) => void>();
17
18
 
18
19
  /** 只用于读取 v1 持久化的 `slotId:resource:<encoded path>`。 */
@@ -45,6 +46,25 @@ export function subscribeChatSlotRequests(
45
46
  };
46
47
  }
47
48
 
49
+ /**
50
+ * Auto-reveal a newly produced deliverable in the right panel:
51
+ * opens the panel when untouched, switches document tabs when already open,
52
+ * and respects an explicit user collapse in the current chat by staging the tab.
53
+ */
54
+ export function revealChatSlot(kind: string, options: Omit<ChatSlotRequest, 'kind'> = {}): void {
55
+ const request = { kind, ...options };
56
+ for (const listener of revealListeners) listener(request);
57
+ }
58
+
59
+ export function subscribeChatSlotReveals(
60
+ listener: (request: ChatSlotRequest) => void,
61
+ ): () => void {
62
+ revealListeners.add(listener);
63
+ return () => {
64
+ revealListeners.delete(listener);
65
+ };
66
+ }
67
+
48
68
  /**
49
69
  * 对话滚动或新产物把右侧内容换到这个栏位。
50
70
  * 和点击不同:栏位关着时不弹出,正在看终端时也不抢走。
@@ -307,3 +307,35 @@ export function openRightPanelTab(
307
307
  if (existing) return { tabs: current.tabs, activeTabId: existing.id };
308
308
  return { tabs: [...current.tabs, requested], activeTabId: requested.id };
309
309
  }
310
+
311
+ /**
312
+ * Auto-reveal a newly generated turn deliverable:
313
+ * - Untouched chat (`current === null`): opens the right panel on this deliverable.
314
+ * - Explicitly collapsed chat (`current.collapsed === true`): stages/updates the tab while keeping it collapsed.
315
+ * - Open panel on terminal: appends the deliverable tab without stealing terminal focus.
316
+ * - Open panel on another document: appends/activates the new deliverable tab.
317
+ */
318
+ export function revealDeliverableRightPanelTab(
319
+ current: RightPanelTabs | null,
320
+ requested: RightPanelTabRecord,
321
+ ): RightPanelTabs {
322
+ if (!current) return { tabs: [requested], activeTabId: requested.id };
323
+ if (current.collapsed) {
324
+ return (
325
+ followRightPanelTab(current, requested) ?? {
326
+ tabs: [requested],
327
+ activeTabId: requested.id,
328
+ collapsed: true,
329
+ }
330
+ );
331
+ }
332
+ const existing = findRightPanelContentTab(current, requested);
333
+ const tab = existing ?? requested;
334
+ const tabs = existing ? current.tabs : [...current.tabs, tab];
335
+ const activeTab = current.tabs.find((item) => item.id === current.activeTabId);
336
+ const activeTabId = activeTab?.kind === 'terminal' ? activeTab.id : tab.id;
337
+ if (current.activeTabId === activeTabId && sameRightPanelTabs(current.tabs, tabs)) {
338
+ return current;
339
+ }
340
+ return { tabs, activeTabId };
341
+ }