@steerable/agent-shell-web 0.14.3 → 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.
Files changed (30) hide show
  1. package/package.json +4 -4
  2. package/src/components/AgentSidebar.tsx +189 -46
  3. package/src/components/ChatHeader.tsx +12 -1
  4. package/src/components/SidebarAccount.tsx +33 -41
  5. package/src/components/chat/AssistantMessage.tsx +36 -10
  6. package/src/components/chat/ChatInput.tsx +308 -131
  7. package/src/components/chat/ChatProjectBadge.tsx +311 -100
  8. package/src/components/chat/ContextUsagePill.tsx +20 -5
  9. package/src/components/chat/ExecPolicyPicker.tsx +72 -67
  10. package/src/components/chat/LocalChatPanel.tsx +33 -35
  11. package/src/components/chat/Markdown.tsx +109 -11
  12. package/src/components/chat/MessageList.tsx +109 -19
  13. package/src/components/chat/ModelPicker.tsx +2 -2
  14. package/src/components/chat/PlanTodoList.tsx +184 -78
  15. package/src/components/chat/SessionTodoList.tsx +63 -72
  16. package/src/components/chat/TurnFilesCard.tsx +270 -112
  17. package/src/components/chat/TurnProcessGroup.tsx +3 -0
  18. package/src/components/chat/TurnProcessTimeline.tsx +13 -0
  19. package/src/components/chat/UserMessage.tsx +8 -1
  20. package/src/components/chat/next-steps-tags.ts +13 -0
  21. package/src/components/chat/process-status.ts +112 -2
  22. package/src/components/chat/todo-list-model.ts +52 -4
  23. package/src/layouts/AgentLayout.tsx +173 -10
  24. package/src/layouts/PanelToggleButton.tsx +27 -9
  25. package/src/layouts/conversation-preview.ts +3 -0
  26. package/src/layouts/request-chat-slot.ts +20 -0
  27. package/src/layouts/right-panel-tabs.ts +32 -0
  28. package/src/lib/chat-mode-store.ts +241 -0
  29. package/src/lib/file-preview-registry.ts +57 -0
  30. package/src/pages/AgentPage.tsx +188 -78
@@ -1,13 +1,23 @@
1
- import { useState, type ReactNode } from 'react';
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ type ReactNode,
8
+ type RefObject,
9
+ } from 'react';
2
10
  import {
3
11
  LuCheck,
4
12
  LuChevronDown,
5
13
  LuFolder,
14
+ LuFolderOpen,
6
15
  LuFolderPen,
7
16
  LuFolderPlus,
8
17
  LuFolderX,
9
18
  LuLoaderCircle,
10
19
  LuPlus,
20
+ LuSearch,
11
21
  } from 'react-icons/lu';
12
22
  import { CreateProjectModal } from '@/components/CreateProjectModal';
13
23
  import { getHostBridge, hasHostBridge } from '@/lib/host-bridge';
@@ -20,80 +30,186 @@ import {
20
30
  import { t } from '@/i18n';
21
31
 
22
32
  /**
23
- * 项目徽章 / 选择器(Codex 式 cwd 指示),渲染在输入框上方的 meta 行里,
24
- * 与专家选择器并排(项目在前)。
25
- *
26
- * 两个导出组件共用同一套按钮 + 上开菜单视觉:
27
- * - ChatProjectBadge — 会话内:显示当前项目(无项目时显示"选择项目"),
28
- * 可关联/移动到其他项目、修改项目目录、移出项目。
29
- * - ProjectPickerButton — 落地页(还没有 chat):受控选择器,选中的
30
- * projectId 在首次发消息建会话时一并传入。
31
- *
32
- * 菜单用透明全屏 backdrop 关外击(一次性菜单,比 click-outside 管线简单)。
33
+ * 项目徽章 / 选择器(WorkBuddy 式项目与本地目录选择器):
34
+ * - ProjectPickerButton — 新建首屏下托盘选择器(搜索项目 + 新建项目 + 选择本地文件夹一步绑定)
35
+ * - ChatProjectBadge — 会话内项目徽章(切换/移动到其他项目、一键关联本地文件夹、修改目录、移出项目)
33
36
  */
34
37
 
38
+ function normalizeFolderPath(raw: string): string {
39
+ return raw.replace(/[\\/]+$/, '') || raw;
40
+ }
41
+
42
+ async function pickOrCreateProjectFromDirectory(
43
+ projects: readonly LocalProject[],
44
+ onProjectsChanged: () => void | Promise<void>,
45
+ ): Promise<LocalProject | null> {
46
+ if (!hasHostBridge()) return null;
47
+ const result = await getHostBridge()!.local?.selectDirectory({
48
+ title: t('Choose local folder'),
49
+ });
50
+ if (!result || result.canceled || result.filePaths.length === 0) return null;
51
+
52
+ const chosen = normalizeFolderPath(result.filePaths[0]!);
53
+ const existing = projects.find(
54
+ (p) => normalizeFolderPath(p.folderPath) === chosen,
55
+ );
56
+ if (existing) return existing;
57
+
58
+ const baseName =
59
+ chosen.split(/[\\/]/).filter(Boolean).pop() || t('Untitled project');
60
+ const created = await createProject({ name: baseName, folderPath: chosen });
61
+ await onProjectsChanged();
62
+ return created.project ?? null;
63
+ }
64
+
65
+ function filterProjectsByQuery(
66
+ list: readonly LocalProject[],
67
+ query: string,
68
+ ): LocalProject[] {
69
+ const q = query.trim().toLowerCase();
70
+ if (!q) return [...list];
71
+ return list.filter(
72
+ (p) =>
73
+ p.name.toLowerCase().includes(q) ||
74
+ p.folderPath.toLowerCase().includes(q),
75
+ );
76
+ }
77
+
35
78
  /* ---------------- 共享内部件 ---------------- */
36
79
 
80
+ function useMenuDismiss(
81
+ rootRef: RefObject<HTMLElement | null>,
82
+ open: boolean,
83
+ onClose: () => void,
84
+ ) {
85
+ useEffect(() => {
86
+ if (!open) return;
87
+ const handlePointerDown = (event: PointerEvent) => {
88
+ const target = event.target;
89
+ if (target instanceof Node && rootRef.current?.contains(target)) {
90
+ return;
91
+ }
92
+ onClose();
93
+ };
94
+ const handleKeyDown = (event: KeyboardEvent) => {
95
+ if (event.key === 'Escape') {
96
+ event.stopPropagation();
97
+ onClose();
98
+ }
99
+ };
100
+ window.addEventListener('pointerdown', handlePointerDown);
101
+ window.addEventListener('keydown', handleKeyDown);
102
+ return () => {
103
+ window.removeEventListener('pointerdown', handlePointerDown);
104
+ window.removeEventListener('keydown', handleKeyDown);
105
+ };
106
+ }, [rootRef, open, onClose]);
107
+ }
108
+
37
109
  function BadgeButton({
38
110
  label,
39
111
  active,
112
+ compact = false,
40
113
  open,
41
114
  busy,
42
115
  onClick,
43
116
  title,
44
117
  }: {
45
118
  label: string;
46
- /** true = 已关联/已选中项目(实心图标);false = 未选择(轻态无边框 + Plus 图标)。 */
47
119
  active: boolean;
120
+ compact?: boolean;
48
121
  open: boolean;
49
122
  busy: boolean;
50
123
  onClick: () => void;
51
124
  title?: string;
52
125
  }) {
126
+ if (compact) {
127
+ return (
128
+ <button
129
+ type="button"
130
+ onClick={onClick}
131
+ disabled={busy}
132
+ title={title}
133
+ aria-label={label}
134
+ aria-haspopup="menu"
135
+ aria-expanded={open}
136
+ data-testid="project-badge-button"
137
+ 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"
138
+ >
139
+ {busy ? (
140
+ <LuLoaderCircle className="h-3.5 w-3.5 shrink-0 animate-spin" />
141
+ ) : (
142
+ <LuFolderPlus className="h-3.5 w-3.5 shrink-0" />
143
+ )}
144
+ </button>
145
+ );
146
+ }
147
+
53
148
  return (
54
149
  <button
55
150
  type="button"
56
151
  onClick={onClick}
57
152
  disabled={busy}
58
153
  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 ${
154
+ aria-haspopup="menu"
155
+ aria-expanded={open}
156
+ data-testid="project-badge-button"
157
+ className={`inline-flex h-6 max-w-full items-center gap-1.5 rounded-full px-2 text-[12px] leading-[1.45] transition-colors hover:bg-agent-foreground/5 hover:text-agent-foreground disabled:opacity-60 ${
60
158
  active
61
- ? 'text-agent-muted-foreground/85'
62
- : 'text-agent-muted-foreground/65'
159
+ ? 'text-agent-foreground/90 font-medium'
160
+ : 'text-agent-muted-foreground'
63
161
  }`}
64
162
  >
65
163
  {busy ? (
66
- <LuLoaderCircle className="h-3 w-3 shrink-0 animate-spin" />
164
+ <LuLoaderCircle className="h-3.5 w-3.5 shrink-0 animate-spin" />
67
165
  ) : active ? (
68
- <LuFolder className="h-3 w-3 shrink-0" />
166
+ <LuFolder className="h-3.5 w-3.5 shrink-0" />
69
167
  ) : (
70
- <LuFolderPlus className="h-3 w-3 shrink-0" />
168
+ <LuFolderPlus className="h-3.5 w-3.5 shrink-0" />
71
169
  )}
72
- <span className="max-w-[220px] truncate font-medium">{label}</span>
170
+ <span className="max-w-[180px] truncate">{label}</span>
73
171
  <LuChevronDown
74
- className={`h-3 w-3 shrink-0 transition-transform ${open ? 'rotate-180' : ''}`}
172
+ className={`h-3 w-3 shrink-0 opacity-75 transition-transform ${open ? 'rotate-180' : ''}`}
75
173
  />
76
174
  </button>
77
175
  );
78
176
  }
79
177
 
80
178
  function MenuShell({
81
- onClose,
82
179
  children,
83
180
  }: {
84
- onClose: () => void;
85
181
  children: ReactNode;
86
182
  }) {
87
183
  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
- </>
184
+ <div
185
+ role="menu"
186
+ className="absolute bottom-full left-0 z-50 mb-1.5 w-64 overflow-hidden rounded-agent-lg border border-agent-border bg-agent-canvas p-1.5 shadow-lg"
187
+ >
188
+ {children}
189
+ </div>
190
+ );
191
+ }
192
+
193
+ function ProjectSearchBox({
194
+ value,
195
+ onChange,
196
+ }: {
197
+ value: string;
198
+ onChange: (next: string) => void;
199
+ }) {
200
+ return (
201
+ <div className="mb-1 flex items-center gap-1.5 rounded-agent-md bg-agent-muted/60 px-2 py-1">
202
+ <LuSearch className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
203
+ <input
204
+ type="text"
205
+ value={value}
206
+ onChange={(e) => onChange(e.target.value)}
207
+ placeholder={t('Search projects…')}
208
+ aria-label={t('Search projects…')}
209
+ data-testid="project-search-input"
210
+ className="min-w-0 flex-1 border-0 bg-transparent text-xs text-agent-foreground placeholder:text-agent-muted-foreground/70 outline-none"
211
+ />
212
+ </div>
97
213
  );
98
214
  }
99
215
 
@@ -138,6 +254,21 @@ function CreateProjectMenuItem({ onClick }: { onClick: () => void }) {
138
254
  );
139
255
  }
140
256
 
257
+ function ChooseLocalFolderMenuItem({ onClick }: { onClick: () => void }) {
258
+ return (
259
+ <button
260
+ type="button"
261
+ role="menuitem"
262
+ data-testid="pick-local-folder"
263
+ onClick={onClick}
264
+ className="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-agent-foreground transition-colors hover:bg-agent-foreground/5"
265
+ >
266
+ <LuFolderOpen className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
267
+ {t('Choose local folder')}
268
+ </button>
269
+ );
270
+ }
271
+
141
272
  function ProjectMenuRow({
142
273
  project,
143
274
  selected,
@@ -174,28 +305,36 @@ export function ChatProjectBadge({
174
305
  onChatProjectChanged,
175
306
  }: {
176
307
  chatId: string;
177
- /** 当前会话绑定的项目;null = 无项目会话(徽章变为"选择项目")。 */
178
308
  project: LocalProject | null;
179
- /** 全部项目(用于关联列表)。 */
180
309
  projects: LocalProject[];
181
- /** 项目本身被修改(改目录)后回调,让父组件刷新项目列表。 */
182
310
  onProjectsChanged: () => void | Promise<void>;
183
- /** 会话归属变化后回调(通常是 refreshChats)。 */
184
311
  onChatProjectChanged: () => void | Promise<void>;
185
312
  }) {
186
313
  const [open, setOpen] = useState(false);
314
+ const [query, setQuery] = useState('');
187
315
  const [createOpen, setCreateOpen] = useState(false);
188
316
  const [busy, setBusy] = useState(false);
189
317
  const [error, setError] = useState<string | null>(null);
318
+ const rootRef = useRef<HTMLDivElement>(null);
319
+ const closeMenu = useCallback(() => {
320
+ setOpen(false);
321
+ setQuery('');
322
+ }, []);
323
+ useMenuDismiss(rootRef, open, closeMenu);
190
324
 
191
325
  const openCreate = () => {
192
- setOpen(false);
326
+ closeMenu();
193
327
  setCreateOpen(true);
194
328
  };
195
329
 
196
- const otherProjects = project
197
- ? projects.filter((p) => p.id !== project.id)
198
- : projects;
330
+ const otherProjects = useMemo(
331
+ () => (project ? projects.filter((p) => p.id !== project.id) : projects),
332
+ [project, projects],
333
+ );
334
+ const filteredOtherProjects = useMemo(
335
+ () => filterProjectsByQuery(otherProjects, query),
336
+ [otherProjects, query],
337
+ );
199
338
 
200
339
  const run = async (action: () => Promise<void>) => {
201
340
  if (busy) return;
@@ -203,7 +342,7 @@ export function ChatProjectBadge({
203
342
  setError(null);
204
343
  try {
205
344
  await action();
206
- setOpen(false);
345
+ closeMenu();
207
346
  } catch (err) {
208
347
  setError(err instanceof Error ? err.message : String(err));
209
348
  } finally {
@@ -217,6 +356,17 @@ export function ChatProjectBadge({
217
356
  await onChatProjectChanged();
218
357
  });
219
358
 
359
+ const pickLocalFolder = () =>
360
+ run(async () => {
361
+ const target = await pickOrCreateProjectFromDirectory(
362
+ projects,
363
+ onProjectsChanged,
364
+ );
365
+ if (!target) return;
366
+ await updateChatProject(chatId, target.id);
367
+ await onChatProjectChanged();
368
+ });
369
+
220
370
  const changeFolder = () =>
221
371
  run(async () => {
222
372
  if (!hasHostBridge() || !project) return;
@@ -229,15 +379,17 @@ export function ChatProjectBadge({
229
379
  });
230
380
 
231
381
  return (
232
- <div className="relative">
382
+ <div ref={rootRef} className="relative">
233
383
  <BadgeButton
234
384
  label={project ? project.name : t('Choose a project')}
235
385
  active={Boolean(project)}
386
+ compact={!project}
236
387
  open={open}
237
388
  busy={busy}
238
389
  onClick={() => {
239
390
  setError(null);
240
- setOpen((v) => !v);
391
+ if (open) closeMenu();
392
+ else setOpen(true);
241
393
  }}
242
394
  title={
243
395
  project
@@ -249,7 +401,11 @@ export function ChatProjectBadge({
249
401
  />
250
402
 
251
403
  {open && (
252
- <MenuShell onClose={() => setOpen(false)}>
404
+ <MenuShell>
405
+ {otherProjects.length > 0 && (
406
+ <ProjectSearchBox value={query} onChange={setQuery} />
407
+ )}
408
+
253
409
  {project ? (
254
410
  <>
255
411
  <MenuSectionLabel>{t('Current project')}</MenuSectionLabel>
@@ -261,7 +417,7 @@ export function ChatProjectBadge({
261
417
  <span className="min-w-0 flex-1 truncate font-medium">
262
418
  {project.name}
263
419
  </span>
264
- <LuCheck className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
420
+ <LuCheck className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
265
421
  </div>
266
422
  <div
267
423
  className="truncate px-2 pb-1 text-[10px] font-mono text-agent-muted-foreground/70"
@@ -280,24 +436,34 @@ export function ChatProjectBadge({
280
436
  <div className="mx-1 my-1 border-t border-agent-border/60" />
281
437
  )}
282
438
  {project && <MenuSectionLabel>{t('Move to')}</MenuSectionLabel>}
283
- <div className="max-h-40 overflow-y-auto">
284
- {otherProjects.map((p) => (
285
- <ProjectMenuRow
286
- key={p.id}
287
- project={p}
288
- onClick={() => void moveTo(p.id)}
289
- />
290
- ))}
291
- </div>
439
+ {filteredOtherProjects.length > 0 ? (
440
+ <div className="max-h-40 overflow-y-auto">
441
+ {filteredOtherProjects.map((p) => (
442
+ <ProjectMenuRow
443
+ key={p.id}
444
+ project={p}
445
+ onClick={() => void moveTo(p.id)}
446
+ />
447
+ ))}
448
+ </div>
449
+ ) : (
450
+ <div className="px-2 py-2 text-center text-[11px] text-agent-muted-foreground/70">
451
+ {t('No matching projects')}
452
+ </div>
453
+ )}
292
454
  </>
293
455
  )}
456
+
294
457
  {!project && projects.length === 0 && (
295
- <>
296
- <div className="px-2 py-1.5 text-[11px] text-agent-muted-foreground/70">
297
- {t('No projects yet')}
298
- </div>
299
- <CreateProjectMenuItem onClick={openCreate} />
300
- </>
458
+ <div className="px-2 py-1.5 text-[11px] text-agent-muted-foreground/70">
459
+ {t('No projects yet')}
460
+ </div>
461
+ )}
462
+
463
+ <div className="mx-1 my-1 border-t border-agent-border/60" />
464
+ <CreateProjectMenuItem onClick={openCreate} />
465
+ {hasHostBridge() && (
466
+ <ChooseLocalFolderMenuItem onClick={() => void pickLocalFolder()} />
301
467
  )}
302
468
 
303
469
  {project && (
@@ -360,29 +526,59 @@ export function ProjectPickerButton({
360
526
  onProjectsChanged,
361
527
  }: {
362
528
  projects: LocalProject[];
363
- /** 当前选中的 projectId;null = 无项目。 */
364
529
  value: string | null;
365
530
  onChange: (projectId: string | null) => void;
366
- /** 新建项目后刷新列表。 */
367
531
  onProjectsChanged: () => void | Promise<void>;
368
532
  }) {
369
533
  const [open, setOpen] = useState(false);
534
+ const [query, setQuery] = useState('');
370
535
  const [createOpen, setCreateOpen] = useState(false);
536
+ const [busy, setBusy] = useState(false);
537
+ const rootRef = useRef<HTMLDivElement>(null);
538
+ const closeMenu = useCallback(() => {
539
+ setOpen(false);
540
+ setQuery('');
541
+ }, []);
542
+ useMenuDismiss(rootRef, open, closeMenu);
371
543
  const selected = value ? (projects.find((p) => p.id === value) ?? null) : null;
544
+ const filteredProjects = useMemo(
545
+ () => filterProjectsByQuery(projects, query),
546
+ [projects, query],
547
+ );
372
548
 
373
549
  const openCreate = () => {
374
- setOpen(false);
550
+ closeMenu();
375
551
  setCreateOpen(true);
376
552
  };
377
553
 
554
+ const handlePickLocalFolder = async () => {
555
+ if (busy) return;
556
+ setBusy(true);
557
+ try {
558
+ const target = await pickOrCreateProjectFromDirectory(
559
+ projects,
560
+ onProjectsChanged,
561
+ );
562
+ if (target) {
563
+ onChange(target.id);
564
+ closeMenu();
565
+ }
566
+ } finally {
567
+ setBusy(false);
568
+ }
569
+ };
570
+
378
571
  return (
379
- <div className="relative">
572
+ <div ref={rootRef} className="relative">
380
573
  <BadgeButton
381
574
  label={selected ? selected.name : t('Choose a project')}
382
575
  active={Boolean(selected)}
383
576
  open={open}
384
- busy={false}
385
- onClick={() => setOpen((v) => !v)}
577
+ busy={busy}
578
+ onClick={() => {
579
+ if (open) closeMenu();
580
+ else setOpen(true);
581
+ }}
386
582
  title={
387
583
  selected
388
584
  ? `${selected.folderPath}\n${t('New chats will be linked to this project')}`
@@ -393,43 +589,58 @@ export function ProjectPickerButton({
393
589
  />
394
590
 
395
591
  {open && (
396
- <MenuShell onClose={() => setOpen(false)}>
592
+ <MenuShell>
593
+ {projects.length > 0 && (
594
+ <ProjectSearchBox value={query} onChange={setQuery} />
595
+ )}
397
596
  <MenuSectionLabel onAdd={openCreate}>{t('Project for new chat')}</MenuSectionLabel>
398
- <button
399
- type="button"
400
- role="menuitem"
401
- onClick={() => {
402
- onChange(null);
403
- setOpen(false);
404
- }}
405
- className="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-agent-foreground transition-colors hover:bg-agent-foreground/5"
406
- >
407
- <LuFolderX className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
408
- <span className="min-w-0 flex-1 truncate">{t('No project')}</span>
409
- {!selected && (
410
- <LuCheck className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
411
- )}
412
- </button>
413
- <div className="max-h-40 overflow-y-auto">
414
- {projects.map((p) => (
415
- <ProjectMenuRow
416
- key={p.id}
417
- project={p}
418
- selected={p.id === value}
419
- onClick={() => {
420
- onChange(p.id);
421
- setOpen(false);
422
- }}
423
- />
424
- ))}
425
- </div>
426
- {projects.length === 0 && (
427
- <>
428
- <div className="px-2 py-1.5 text-[11px] text-agent-muted-foreground/70">
429
- {t('No projects yet')}
597
+ {!query.trim() && (
598
+ <button
599
+ type="button"
600
+ role="menuitem"
601
+ onClick={() => {
602
+ onChange(null);
603
+ closeMenu();
604
+ }}
605
+ className="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs text-agent-foreground transition-colors hover:bg-agent-foreground/5"
606
+ >
607
+ <LuFolderX className="h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
608
+ <span className="min-w-0 flex-1 truncate">{t('No project')}</span>
609
+ {!selected && (
610
+ <LuCheck className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
611
+ )}
612
+ </button>
613
+ )}
614
+ {projects.length > 0 ? (
615
+ filteredProjects.length > 0 ? (
616
+ <div className="max-h-40 overflow-y-auto">
617
+ {filteredProjects.map((p) => (
618
+ <ProjectMenuRow
619
+ key={p.id}
620
+ project={p}
621
+ selected={p.id === value}
622
+ onClick={() => {
623
+ onChange(p.id);
624
+ closeMenu();
625
+ }}
626
+ />
627
+ ))}
430
628
  </div>
431
- <CreateProjectMenuItem onClick={openCreate} />
432
- </>
629
+ ) : (
630
+ <div className="px-2 py-2 text-center text-[11px] text-agent-muted-foreground/70">
631
+ {t('No matching projects')}
632
+ </div>
633
+ )
634
+ ) : (
635
+ <div className="px-2 py-1.5 text-[11px] text-agent-muted-foreground/70">
636
+ {t('No projects yet')}
637
+ </div>
638
+ )}
639
+
640
+ <div className="mx-1 my-1 border-t border-agent-border/60" />
641
+ <CreateProjectMenuItem onClick={openCreate} />
642
+ {hasHostBridge() && (
643
+ <ChooseLocalFolderMenuItem onClick={() => void handlePickLocalFolder()} />
433
644
  )}
434
645
  </MenuShell>
435
646
  )}
@@ -144,6 +144,8 @@ export function ContextUsagePill({
144
144
  const rawPct = Math.round(dominantRatio * 100);
145
145
  const dominantPct = estTokens > 0 || estBytes > 0 ? Math.max(1, rawPct) : 0;
146
146
  const isElevated = dominantRatio >= 0.7;
147
+ const isQuietLow = dominantRatio < 0.5;
148
+ const showByteDominantHint = isByteDominant && byteRatio - tokenRatio >= 0.25;
147
149
  const dominantSummary = isByteDominant
148
150
  ? formatMegabytes(estBytes)
149
151
  : formatCompactCount(estTokens);
@@ -156,7 +158,9 @@ export function ContextUsagePill({
156
158
  ? 'border-red-500/40 bg-red-500/10 px-2 text-red-600 dark:text-red-400'
157
159
  : isElevated
158
160
  ? 'border-amber-500/40 bg-amber-500/10 px-2 text-amber-600 dark:text-amber-400'
159
- : 'border-transparent bg-transparent px-1.5 text-agent-muted-foreground/80 hover:bg-agent-foreground/5 hover:text-agent-foreground';
161
+ : isQuietLow
162
+ ? 'border-transparent bg-transparent px-1 text-agent-muted-foreground/75 hover:bg-agent-foreground/5 hover:text-agent-foreground'
163
+ : 'border-transparent bg-transparent px-1.5 text-agent-muted-foreground/80 hover:bg-agent-foreground/5 hover:text-agent-foreground';
160
164
 
161
165
  const barColor =
162
166
  dominantRatio >= 0.85
@@ -196,19 +200,22 @@ export function ContextUsagePill({
196
200
  type="button"
197
201
  data-testid="context-usage-pill"
198
202
  onClick={() => setOpen((prev) => !prev)}
203
+ aria-label={`${t('Context window and payload usage')} (${dominantPct}%)`}
199
204
  title={`${t('Context window and payload usage')} (${tooltipDetail})`}
200
205
  className={`inline-flex h-6 items-center gap-1 rounded-full border text-[11px] leading-tight tabular-nums transition-colors ${toneClass}`}
201
206
  >
202
207
  <ContextRing ratio={dominantRatio} />
203
- <span>
204
- {isElevated ? `${dominantSummary} · ${dominantPct}%` : `${dominantPct}%`}
205
- </span>
208
+ {!isQuietLow && (
209
+ <span>
210
+ {isElevated ? `${dominantSummary} · ${dominantPct}%` : `${dominantPct}%`}
211
+ </span>
212
+ )}
206
213
  </button>
207
214
 
208
215
  {open && (
209
216
  <div
210
217
  data-testid="context-usage-popover"
211
- className="absolute bottom-full left-0 z-50 mb-2 w-72 rounded-agent-lg border border-agent-border bg-agent-canvas p-3 text-xs shadow-lg"
218
+ className="absolute bottom-full right-0 z-50 mb-2 w-72 max-w-[calc(100vw-2rem)] rounded-agent-lg border border-agent-border bg-agent-canvas p-3 text-xs shadow-lg"
212
219
  >
213
220
  <div className="font-medium text-agent-foreground">
214
221
  {t('Context budget')}
@@ -245,6 +252,14 @@ export function ContextUsagePill({
245
252
  style={{ width: `${Math.max(2, Math.round(byteRatio * 100))}%` }}
246
253
  />
247
254
  </div>
255
+ {showByteDominantHint && (
256
+ <div
257
+ data-testid="context-byte-dominant-hint"
258
+ className="mt-1 text-[11px] text-agent-muted-foreground"
259
+ >
260
+ {t('Primarily used by embedded images or attachments.')}
261
+ </div>
262
+ )}
248
263
  </div>
249
264
 
250
265
  {cacheHitPct !== null && (