@koinzhang/paseo-plugin-inbox 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
1
  import type { PluginTheme } from "@getpaseo/plugin";
2
- import { type PluginSurfaceProps, usePaseo, useRpc } from "@getpaseo/plugin/client";
3
- import { Icon, ScrollView, TextInput, useToast } from "@getpaseo/plugin/client/ui";
2
+ import { type PluginSurfaceProps, useComposers, usePaseo, useRpc } from "@getpaseo/plugin/client";
3
+ import { copyText, Icon, Markdown, ScrollView, TextInput, useToast } from "@getpaseo/plugin/client/ui";
4
4
  import { keepPreviousData, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
5
5
  import {
6
6
  type ComponentProps,
7
- type ComponentRef,
8
7
  Fragment,
9
8
  type ReactNode,
9
+ useCallback,
10
10
  useEffect,
11
11
  useMemo,
12
12
  useRef,
13
13
  useState,
14
14
  } from "react";
15
- import { PanResponder, Platform, Pressable, Text, View } from "react-native";
15
+ import { Animated, Easing, PanResponder, Platform, Pressable, Text, View } from "react-native";
16
16
  import {
17
17
  agentCandidates,
18
18
  agentStates,
@@ -36,17 +36,23 @@ import { fetchLastExchange } from "./last-exchange.ts";
36
36
  import { AgentIcon, PermissionBadge } from "./agent-status.tsx";
37
37
  import { inboxListSort, visibleInboxFilters } from "../shared/filter-settings.ts";
38
38
  import { itemTitle } from "../shared/item-title.ts";
39
- import { isEmptyNote } from "../shared/note.ts";
39
+ import { formatItemTime, workspaceItemSubtitle } from "./item-subtitle.ts";
40
+ import { isEmptyNote, syncNoteText } from "../shared/note.ts";
41
+ import { insertNoteIntoComposer } from "./note-actions.ts";
42
+ import { KindFilterMenu, KindFilterMenuPanel } from "./kind-filter-menu.tsx";
43
+ import { toggleInboxKind, toggleInboxSelection } from "./kind-filter.ts";
44
+ import { noteFieldFocusBorder } from "./note-detail-styles.ts";
45
+ import { showsNoteRowActions } from "./note-row-actions.ts";
40
46
  import {
41
47
  type DraftTags,
42
- notifyItemsChanged,
43
48
  onItemsChanged,
44
49
  onSelectionRequest,
45
50
  type SelectionRequest,
46
51
  takeSelection,
47
52
  } from "./selection.ts";
48
53
  import { useInboxFilters } from "./use-inbox-filters.ts";
49
- import { type HorizontalScrollNode, trackHorizontalDrag, wheelScrollsHorizontally } from "./web.ts";
54
+ import { trackHorizontalDrag } from "./web.ts";
55
+ import { shouldSelectFirstItem } from "./default-selection.ts";
50
56
 
51
57
  /**
52
58
  * `id` is the open item; `draft` is non-null for an unsaved note.
@@ -79,13 +85,7 @@ const STATES_KEY = ["inbox", "agent-states"] as const;
79
85
  const CANDIDATES_KEY = ["inbox", "agent-candidates"] as const;
80
86
  const TAG_OPTIONS_KEY = ["inbox", "tag-options"] as const;
81
87
  const SAVE_DELAY_MS = 600;
82
-
83
- const FILTERS: Array<{ id: ItemKind | "all"; label: string }> = [
84
- { id: "all", label: "All" },
85
- { id: "agent", label: "Agents" },
86
- { id: "note", label: "Notes" },
87
- { id: "scratch", label: "Scratch" },
88
- ];
88
+ type NoteComposer = Parameters<typeof insertNoteIntoComposer>[0];
89
89
 
90
90
  /** Tapping the sort button steps through these in order. */
91
91
  const SORTS: Array<{ id: ItemSort; label: string; icon: string }> = [
@@ -96,6 +96,9 @@ const SORTS: Array<{ id: ItemSort; label: string; icon: string }> = [
96
96
  ];
97
97
 
98
98
  const LIST_WIDTH = { initial: 360, min: 280, max: 640 };
99
+ const SEARCH_ANIM_MS = 220;
100
+ const SEARCH_CLOSE_ANIM_MS = 160;
101
+ const TOOLBAR_HEIGHT = 24;
99
102
  const clampListWidth = (width: number) => Math.min(LIST_WIDTH.max, Math.max(LIST_WIDTH.min, width));
100
103
  /** Keeps the dragged width while the app runs, across surface remounts. */
101
104
  let rememberedListWidth = LIST_WIDTH.initial;
@@ -111,14 +114,15 @@ type Styles = ReturnType<typeof createStyles>;
111
114
  const noOutline = Platform.OS === "web" ? ({ outlineStyle: "none" } as object) : {};
112
115
  const resizeCursor = Platform.OS === "web" ? ({ cursor: "col-resize" } as object) : {};
113
116
 
114
- /** Swaps the accent focus ring for a muted border, like Customize's search box. */
117
+ /** Swaps the accent focus ring for a muted border on bordered inputs. */
115
118
  function Field({ styles, style, ...props }: ComponentProps<typeof TextInput> & { styles: Styles }) {
116
119
  const [focused, setFocused] = useState(false);
120
+ const borderless = style === styles.detailTitleInput || style === styles.editor;
117
121
  return (
118
122
  <TextInput
119
123
  placeholderTextColor={styles.placeholderColor}
120
124
  {...props}
121
- style={[style, focused ? styles.inputFocused : null]}
125
+ style={[style, noteFieldFocusBorder({ borderless, focused }) ? styles.inputFocused : null]}
122
126
  onFocus={(e) => {
123
127
  setFocused(true);
124
128
  props.onFocus?.(e);
@@ -131,11 +135,25 @@ function Field({ styles, style, ...props }: ComponentProps<typeof TextInput> & {
131
135
  );
132
136
  }
133
137
 
134
- function createStyles(theme: PluginTheme, compact: boolean) {
138
+ function createStyles(theme: PluginTheme, compact: boolean, workspace: boolean) {
135
139
  const c = theme.colors;
136
140
  return {
137
- screen: { flex: 1, backgroundColor: c.surface0, flexDirection: "row" as const },
141
+ screen: { flex: 1, backgroundColor: workspace ? "transparent" : c.surface0, flexDirection: "row" as const },
138
142
  listPane: { overflow: "hidden" as const },
143
+ listChrome: { position: "relative" as const },
144
+ filterMenuBackdrop: {
145
+ position: "absolute" as const,
146
+ top: 0,
147
+ left: 0,
148
+ right: 0,
149
+ bottom: 0,
150
+ zIndex: 30,
151
+ },
152
+ filterMenuPosition: {
153
+ position: "absolute" as const,
154
+ zIndex: 31,
155
+ overflow: "visible" as const,
156
+ },
139
157
  divider: {
140
158
  width: 9,
141
159
  marginHorizontal: -4,
@@ -145,8 +163,54 @@ function createStyles(theme: PluginTheme, compact: boolean) {
145
163
  },
146
164
  dividerLine: { width: 1, flex: 1, backgroundColor: c.border },
147
165
  detailPane: { flex: 1, padding: compact ? 16 : 24, gap: 12 },
148
- toolbar: { padding: compact ? 12 : 16, gap: 10, borderBottomWidth: 1, borderColor: c.border },
166
+ detailBack: { marginLeft: -6 },
167
+ toolbar: { padding: compact ? 12 : 16, gap: 10, overflow: "visible" as const },
149
168
  row: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8 },
169
+ toolbarRow: { flexDirection: "row" as const, alignItems: "center" as const, height: TOOLBAR_HEIGHT },
170
+ toolbarSearchSlot: {
171
+ flex: 1,
172
+ minWidth: 0,
173
+ height: TOOLBAR_HEIGHT,
174
+ flexDirection: "row" as const,
175
+ justifyContent: "flex-end" as const,
176
+ overflow: "hidden" as const,
177
+ },
178
+ toolbarSearchField: {
179
+ height: TOOLBAR_HEIGHT,
180
+ flexDirection: "row" as const,
181
+ alignItems: "center" as const,
182
+ gap: 6,
183
+ paddingHorizontal: 10,
184
+ borderWidth: 1,
185
+ borderColor: c.border,
186
+ borderRadius: TOOLBAR_HEIGHT / 2,
187
+ backgroundColor: c.surface1,
188
+ overflow: "hidden" as const,
189
+ },
190
+ toolbarSearchInput: {
191
+ flex: 1,
192
+ minWidth: 0,
193
+ height: TOOLBAR_HEIGHT - 2,
194
+ padding: 0,
195
+ margin: 0,
196
+ color: c.foreground,
197
+ fontSize: 12,
198
+ lineHeight: 18,
199
+ ...noOutline,
200
+ },
201
+ toolbarActions: {
202
+ flexDirection: "row" as const,
203
+ alignItems: "center" as const,
204
+ gap: 2,
205
+ flexShrink: 0,
206
+ marginLeft: 2,
207
+ },
208
+ itemRow: { flexDirection: "row" as const, alignItems: "center" as const, gap: 8, position: "relative" as const },
209
+ itemActions: { flexDirection: "row" as const, alignItems: "center" as const, flexShrink: 0 },
210
+ itemActionsOverlay: { position: "absolute" as const, right: 0, top: 0, bottom: 0 },
211
+ detailMeta: { flexDirection: "row" as const, alignItems: "center" as const, justifyContent: "flex-end" as const, gap: 8 },
212
+ detailTags: { flexDirection: "row" as const, alignItems: "center" as const, gap: 6, flex: 1, minWidth: 0 },
213
+ itemActionDivider: { width: 1, height: 16, marginHorizontal: 3, backgroundColor: c.border },
150
214
  wrap: { flexDirection: "row" as const, flexWrap: "wrap" as const, gap: 6 },
151
215
  input: {
152
216
  color: c.foreground,
@@ -161,10 +225,26 @@ function createStyles(theme: PluginTheme, compact: boolean) {
161
225
  },
162
226
  inputFocused: { borderColor: c.foregroundMuted },
163
227
  placeholderColor: c.foregroundMuted,
228
+ noteEditor: { flex: 1, gap: 10 },
229
+ noteFields: { flex: 1, backgroundColor: "transparent" },
230
+ detailTitleInput: {
231
+ flex: 1,
232
+ minWidth: 0,
233
+ color: c.foreground,
234
+ backgroundColor: "transparent",
235
+ borderWidth: 0,
236
+ paddingHorizontal: 0,
237
+ paddingVertical: 0,
238
+ fontSize: compact ? 18 : 20,
239
+ fontWeight: "600" as const,
240
+ ...noOutline,
241
+ },
164
242
  chip: (active: boolean) => ({
165
243
  flexDirection: "row" as const,
166
244
  alignItems: "center" as const,
167
245
  gap: 4,
246
+ minWidth: 0,
247
+ flexShrink: 1,
168
248
  paddingHorizontal: 10,
169
249
  paddingVertical: 5,
170
250
  borderRadius: 999,
@@ -175,16 +255,17 @@ function createStyles(theme: PluginTheme, compact: boolean) {
175
255
  chipText: (active: boolean) => ({
176
256
  color: active ? c.accentForeground : c.foregroundMuted,
177
257
  fontSize: 12,
258
+ flexShrink: 1,
259
+ minWidth: 0,
178
260
  }),
179
261
  item: (selected: boolean) => ({
180
262
  paddingHorizontal: compact ? 12 : 16,
181
263
  paddingVertical: 10,
182
264
  gap: 4,
183
- borderBottomWidth: 1,
184
- borderColor: c.border,
185
265
  backgroundColor: selected ? c.surface2 : "transparent",
186
266
  }),
187
- itemTitle: { color: c.foreground, fontSize: 14, flex: 1 },
267
+ itemDivider: { height: 1, marginHorizontal: compact ? 12 : 16, backgroundColor: c.border },
268
+ itemTitle: { color: c.foreground, fontSize: 14, flex: 1, minWidth: 0 },
188
269
  muted: { color: c.foregroundMuted, fontSize: 12 },
189
270
  struck: { textDecorationLine: "line-through" as const },
190
271
  badge: (tone: "warning" | "danger" | "success") => ({
@@ -194,25 +275,14 @@ function createStyles(theme: PluginTheme, compact: boolean) {
194
275
  }),
195
276
  heading: { color: c.foreground, fontSize: compact ? 18 : 20, fontWeight: "600" as const },
196
277
  body: { color: c.foreground, fontSize: 14 },
197
- message: {
198
- color: c.foreground,
199
- fontSize: 13,
200
- lineHeight: 18,
201
- backgroundColor: c.surface1,
202
- borderColor: c.border,
203
- borderWidth: 1,
204
- borderRadius: 8,
205
- padding: 10,
206
- },
207
278
  editor: {
208
279
  flex: 1,
209
280
  minHeight: 200,
210
281
  color: c.foreground,
211
- backgroundColor: c.surface1,
212
- borderColor: c.border,
213
- borderWidth: 1,
214
- borderRadius: 8,
215
- padding: 12,
282
+ backgroundColor: "transparent",
283
+ borderWidth: 0,
284
+ paddingHorizontal: 0,
285
+ paddingVertical: 12,
216
286
  fontSize: 14,
217
287
  textAlignVertical: "top" as const,
218
288
  ...noOutline,
@@ -229,6 +299,24 @@ function createStyles(theme: PluginTheme, compact: boolean) {
229
299
  backgroundColor: kind === "primary" ? c.accent : "transparent",
230
300
  }),
231
301
  iconButton: { paddingHorizontal: 8, paddingVertical: 8 },
302
+ toolbarIconButton: (active: boolean) => ({
303
+ width: TOOLBAR_HEIGHT,
304
+ height: TOOLBAR_HEIGHT,
305
+ alignItems: "center" as const,
306
+ justifyContent: "center" as const,
307
+ borderRadius: 6,
308
+ backgroundColor: active ? c.surface2 : "transparent",
309
+ flexShrink: 0,
310
+ }),
311
+ rowIconButton: (pressed: boolean) => ({
312
+ width: 28,
313
+ height: 28,
314
+ alignItems: "center" as const,
315
+ justifyContent: "center" as const,
316
+ borderRadius: 6,
317
+ backgroundColor: pressed ? c.surface2 : "transparent",
318
+ flexShrink: 0,
319
+ }),
232
320
  buttonText: (kind: "primary" | "plain" | "danger") => ({
233
321
  color:
234
322
  kind === "primary" ? c.accentForeground : kind === "danger" ? c.statusDanger : c.foreground,
@@ -238,6 +326,104 @@ function createStyles(theme: PluginTheme, compact: boolean) {
238
326
  };
239
327
  }
240
328
 
329
+ function ToolbarIconButton({
330
+ styles,
331
+ theme,
332
+ icon,
333
+ accessibilityLabel,
334
+ onPress,
335
+ active = false,
336
+ }: {
337
+ styles: Styles;
338
+ theme: PluginTheme;
339
+ icon?: string;
340
+ accessibilityLabel: string;
341
+ onPress: () => void;
342
+ active?: boolean;
343
+ }) {
344
+ return (
345
+ <Pressable
346
+ accessibilityRole="button"
347
+ accessibilityLabel={accessibilityLabel}
348
+ accessibilityHint={Platform.OS === "web" ? accessibilityLabel : undefined}
349
+ accessibilityState={{ expanded: active }}
350
+ hitSlop={8}
351
+ onPress={onPress}
352
+ style={({ pressed }) => styles.toolbarIconButton(active || pressed)}
353
+ >
354
+ {icon ? <Icon name={icon} size={16} color={theme.colors.foregroundMuted} /> : null}
355
+ </Pressable>
356
+ );
357
+ }
358
+
359
+ function RowIconButton({
360
+ styles,
361
+ theme,
362
+ icon,
363
+ accessibilityLabel,
364
+ onPress,
365
+ disabled,
366
+ color,
367
+ }: {
368
+ styles: Styles;
369
+ theme: PluginTheme;
370
+ icon: string;
371
+ accessibilityLabel: string;
372
+ onPress: () => void;
373
+ disabled?: boolean;
374
+ color?: string;
375
+ }) {
376
+ return (
377
+ <Pressable
378
+ accessibilityRole="button"
379
+ accessibilityLabel={accessibilityLabel}
380
+ accessibilityHint={Platform.OS === "web" ? accessibilityLabel : undefined}
381
+ hitSlop={8}
382
+ disabled={disabled}
383
+ onPress={onPress}
384
+ style={({ pressed }) => [styles.rowIconButton(pressed), disabled ? { opacity: 0.45 } : null]}
385
+ >
386
+ <Icon name={icon} size={14} color={color ?? theme.colors.foregroundMuted} />
387
+ </Pressable>
388
+ );
389
+ }
390
+
391
+ function useNoteActions(body: string, composer: NoteComposer | undefined) {
392
+ const toast = useToast();
393
+ const [copying, setCopying] = useState(false);
394
+ const [sending, setSending] = useState(false);
395
+ const copy = async () => {
396
+ setCopying(true);
397
+ try {
398
+ await copyText(body);
399
+ toast.show("Copied", { variant: "success" });
400
+ } catch (error) {
401
+ toast.error(`Could not copy: ${errorText(error)}`);
402
+ } finally {
403
+ setCopying(false);
404
+ }
405
+ };
406
+ const send = async () => {
407
+ if (!composer) return;
408
+ setSending(true);
409
+ try {
410
+ await insertNoteIntoComposer(composer, body);
411
+ toast.show("Inserted into the current agent's composer", { variant: "success" });
412
+ } catch (error) {
413
+ toast.error(`Could not insert note: ${errorText(error)}`);
414
+ } finally {
415
+ setSending(false);
416
+ }
417
+ };
418
+ return {
419
+ copy: () => void copy(),
420
+ send: () => void send(),
421
+ copying,
422
+ sending,
423
+ canSend: Boolean(composer),
424
+ };
425
+ }
426
+
241
427
  function errorText(error: unknown): string {
242
428
  return error instanceof Error ? error.message : String(error);
243
429
  }
@@ -281,7 +467,202 @@ function Button({
281
467
  );
282
468
  }
283
469
 
284
- const KIND_ICON: Record<ItemKind, string> = { agent: "Bot", note: "NotebookText", scratch: "StickyNote" };
470
+ function DetailActionGroup({
471
+ entries,
472
+ styles,
473
+ theme,
474
+ }: {
475
+ entries: Array<{
476
+ key: string;
477
+ icon: string;
478
+ label: string;
479
+ onPress: () => void;
480
+ disabled?: boolean;
481
+ color?: string;
482
+ }>;
483
+ styles: Styles;
484
+ theme: PluginTheme;
485
+ }) {
486
+ return (
487
+ <View style={styles.itemActions}>
488
+ {entries.map((entry, index) => (
489
+ <Fragment key={entry.key}>
490
+ {index ? <View style={styles.itemActionDivider} /> : null}
491
+ <RowIconButton
492
+ styles={styles}
493
+ theme={theme}
494
+ icon={entry.icon}
495
+ accessibilityLabel={entry.label}
496
+ disabled={entry.disabled}
497
+ onPress={entry.onPress}
498
+ color={entry.color}
499
+ />
500
+ </Fragment>
501
+ ))}
502
+ </View>
503
+ );
504
+ }
505
+
506
+ const KIND_ICON: Record<ItemKind, string> = { agent: "Bot", note: "FileText" };
507
+
508
+ function useAgentRestore(item: Item) {
509
+ const unarchive = useRpc(unarchiveAgent);
510
+ const queryClient = useQueryClient();
511
+ const toast = useToast();
512
+ const mutation = useMutation({
513
+ mutationFn: () => unarchive({ agentId: item.agentId! }),
514
+ onSuccess: ({ restoredWorkspace }) => {
515
+ toast.show(restoredWorkspace ? "Workspace and agent restored" : "Agent unarchived", { variant: "success" });
516
+ void queryClient.invalidateQueries({ queryKey: STATES_KEY });
517
+ },
518
+ onError: (error) => toast.error(errorText(error)),
519
+ });
520
+ return {
521
+ pending: mutation.isPending,
522
+ restore: () => mutation.mutate(),
523
+ };
524
+ }
525
+
526
+ function ItemActions({
527
+ item,
528
+ state,
529
+ composer,
530
+ selected,
531
+ visible,
532
+ navigation,
533
+ styles,
534
+ theme,
535
+ onDeleted,
536
+ onBusyChange,
537
+ containerStyle,
538
+ onWidthChange,
539
+ }: {
540
+ item: Item;
541
+ state: AgentState | undefined;
542
+ composer: NoteComposer | undefined;
543
+ selected: boolean;
544
+ visible: boolean;
545
+ navigation: PluginSurfaceProps["navigation"];
546
+ styles: Styles;
547
+ theme: PluginTheme;
548
+ onDeleted: () => void;
549
+ onBusyChange: (busy: boolean) => void;
550
+ containerStyle?: object;
551
+ onWidthChange?: (width: number) => void;
552
+ }) {
553
+ const update = useRpc(updateItem);
554
+ const remove = useRpc(deleteItem);
555
+ const queryClient = useQueryClient();
556
+ const toast = useToast();
557
+ const [pinning, setPinning] = useState(false);
558
+ const [deleting, setDeleting] = useState(false);
559
+ const noteActions = useNoteActions(item.body, composer);
560
+ const restore = useAgentRestore(item);
561
+ const canOpen = item.kind === "agent" && state === "active" && Boolean(navigation && item.agentId);
562
+ const busy = pinning || deleting || restore.pending || noteActions.copying || noteActions.sending;
563
+ useEffect(() => onBusyChange(busy), [busy, onBusyChange]);
564
+ const run = async (kind: "pin" | "delete") => {
565
+ const setBusy = kind === "pin" ? setPinning : setDeleting;
566
+ setBusy(true);
567
+ try {
568
+ if (kind === "pin") await update({ id: item.id, pinned: !item.pinned });
569
+ else await remove({ id: item.id });
570
+ if (kind === "delete" && selected) onDeleted();
571
+ await queryClient.invalidateQueries({ queryKey: ["inbox"] });
572
+ } catch (error) {
573
+ toast.error(errorText(error));
574
+ await queryClient.invalidateQueries({ queryKey: ["inbox"] });
575
+ } finally {
576
+ setBusy(false);
577
+ }
578
+ };
579
+ const actions = item.kind === "agent"
580
+ ? [
581
+ state === "archived" ? {
582
+ key: "unarchive",
583
+ icon: "ArchiveRestore",
584
+ label: restore.pending ? "Unarchiving" : "Unarchive",
585
+ disabled: restore.pending,
586
+ onPress: restore.restore,
587
+ } : {
588
+ key: "open",
589
+ icon: "SquareArrowOutUpRight",
590
+ label: canOpen ? "Open agent" : "Agent unavailable to open",
591
+ disabled: !canOpen,
592
+ onPress: () => {
593
+ if (canOpen) navigation!.openAgent({ agentId: item.agentId! });
594
+ },
595
+ },
596
+ {
597
+ key: "pin",
598
+ icon: item.pinned ? "PinOff" : "Pin",
599
+ label: item.pinned ? "Unpin" : "Pin",
600
+ disabled: pinning,
601
+ onPress: () => void run("pin"),
602
+ },
603
+ {
604
+ key: "delete",
605
+ icon: "StarOff",
606
+ label: "Remove from Inbox",
607
+ disabled: deleting,
608
+ color: theme.colors.statusDanger,
609
+ onPress: () => void run("delete"),
610
+ },
611
+ ]
612
+ : [
613
+ {
614
+ key: "pin",
615
+ icon: item.pinned ? "PinOff" : "Pin",
616
+ label: item.pinned ? "Unpin" : "Pin",
617
+ disabled: pinning,
618
+ onPress: () => void run("pin"),
619
+ },
620
+ {
621
+ key: "copy",
622
+ icon: "Copy",
623
+ label: "Copy note",
624
+ disabled: noteActions.copying,
625
+ onPress: noteActions.copy,
626
+ },
627
+ {
628
+ key: "send",
629
+ icon: "Send",
630
+ label: composer ? "Send note to current agent" : "No current agent available",
631
+ disabled: !composer || noteActions.sending,
632
+ onPress: noteActions.send,
633
+ },
634
+ {
635
+ key: "delete",
636
+ icon: "Trash2",
637
+ label: "Delete",
638
+ disabled: deleting,
639
+ color: theme.colors.statusDanger,
640
+ onPress: () => void run("delete"),
641
+ },
642
+ ];
643
+ return (
644
+ <View
645
+ style={[styles.itemActions, containerStyle, { opacity: visible || busy ? 1 : 0 }]}
646
+ pointerEvents={visible || busy ? "auto" : "none"}
647
+ onLayout={onWidthChange ? (event) => onWidthChange(event.nativeEvent.layout.width) : undefined}
648
+ >
649
+ {actions.map((action, index) => (
650
+ <Fragment key={action.key}>
651
+ {index ? <View style={styles.itemActionDivider} /> : null}
652
+ <RowIconButton
653
+ styles={styles}
654
+ theme={theme}
655
+ icon={action.icon}
656
+ accessibilityLabel={action.label}
657
+ disabled={action.disabled}
658
+ color={"color" in action ? action.color : undefined}
659
+ onPress={action.onPress}
660
+ />
661
+ </Fragment>
662
+ ))}
663
+ </View>
664
+ );
665
+ }
285
666
 
286
667
  /** Project and workspace tags of an item; archived ones are marked. */
287
668
  function itemTags(item: Item, archived: Archived): Array<{ label: string; archived: boolean }> {
@@ -300,90 +681,136 @@ function ItemRow({
300
681
  selected,
301
682
  state,
302
683
  live,
684
+ agentUpdatedAt,
303
685
  archived,
304
686
  hideWorkspaceId,
687
+ composer,
688
+ navigation,
305
689
  styles,
306
690
  theme,
307
691
  onPress,
692
+ onDeleted,
308
693
  }: {
309
694
  item: Item;
310
695
  selected: boolean;
311
696
  state: AgentState | undefined;
312
697
  live: AgentLive | undefined;
698
+ agentUpdatedAt: string | null | undefined;
313
699
  archived: Archived;
314
700
  /** The panel's own workspace, left out of the subtitle. */
315
701
  hideWorkspaceId: string | null;
702
+ composer: NoteComposer | undefined;
703
+ navigation: PluginSurfaceProps["navigation"];
316
704
  styles: Styles;
317
705
  theme: PluginTheme;
318
706
  onPress: () => void;
707
+ onDeleted: () => void;
319
708
  }) {
709
+ const [hovered, setHovered] = useState(false);
710
+ const [busy, setBusy] = useState(false);
711
+ const reportBusy = useCallback((pending: boolean) => setBusy(pending), []);
712
+ const [actionsWidth, setActionsWidth] = useState(0);
713
+ const overlayActions = Platform.OS === "web";
714
+ const showActions = showsNoteRowActions({
715
+ web: Platform.OS === "web",
716
+ hovered,
717
+ busy,
718
+ });
320
719
  const agentState = state;
321
720
  const status = item.kind === "agent" ? describeAgentStatus(agentState, live) : null;
322
721
  const tags = itemTags(
323
722
  hideWorkspaceId && item.workspaceId === hideWorkspaceId ? { ...item, workspaceId: null } : item,
324
723
  archived,
325
724
  );
326
- const subtitle = [
725
+ const subtitle = hideWorkspaceId ? workspaceItemSubtitle(item, agentUpdatedAt) : [
327
726
  ...tags,
328
- ...[item.kind === "agent" ? item.agentSnapshot?.provider : null, new Date(item.updatedAt).toLocaleDateString()]
727
+ ...[item.kind === "agent" ? item.agentSnapshot?.provider : null, formatItemTime(item.updatedAt)]
329
728
  .filter((label): label is string => Boolean(label))
330
729
  .map((label) => ({ label, archived: false })),
331
730
  ];
332
731
  return (
333
- <Pressable
334
- accessibilityRole="button"
335
- accessibilityLabel={status ? `${itemTitle(item)}, ${status.label}` : itemTitle(item)}
336
- onPress={onPress}
337
- style={styles.item(selected)}
732
+ <View
733
+ {...({
734
+ onPointerEnter: () => setHovered(true),
735
+ onPointerLeave: () => setHovered(false),
736
+ } as object)}
338
737
  >
339
- <View style={styles.row}>
340
- {item.kind === "agent" ? (
341
- <AgentIcon state={agentState} live={live} size={14} theme={theme} />
342
- ) : (
343
- <Icon name={KIND_ICON[item.kind]} size={14} color={theme.colors.foregroundMuted} />
344
- )}
345
- <Text style={styles.itemTitle} numberOfLines={1}>
346
- {itemTitle(item)}
738
+ <Pressable
739
+ accessibilityRole="button"
740
+ accessibilityLabel={status ? `${itemTitle(item)}, ${status.label}` : itemTitle(item)}
741
+ onPress={onPress}
742
+ style={styles.item(selected)}
743
+ >
744
+ <View style={styles.itemRow}>
745
+ {item.kind === "agent" ? (
746
+ <AgentIcon state={agentState} live={live} size={14} theme={theme} />
747
+ ) : (
748
+ <Icon name={KIND_ICON[item.kind]} size={14} color={theme.colors.foregroundMuted} />
749
+ )}
750
+ <Text
751
+ style={[styles.itemTitle, overlayActions ? { paddingRight: showActions ? actionsWidth + 8 : 0 } : null]}
752
+ numberOfLines={1}
753
+ >
754
+ {itemTitle(item)}
755
+ </Text>
756
+ {item.kind === "agent" ? <PermissionBadge state={agentState} live={live} theme={theme} /> : null}
757
+ <ItemActions
758
+ item={item}
759
+ state={agentState}
760
+ composer={composer}
761
+ selected={selected}
762
+ visible={showActions}
763
+ navigation={navigation}
764
+ styles={styles}
765
+ theme={theme}
766
+ onDeleted={onDeleted}
767
+ onBusyChange={reportBusy}
768
+ containerStyle={overlayActions ? styles.itemActionsOverlay : undefined}
769
+ onWidthChange={overlayActions ? setActionsWidth : undefined}
770
+ />
771
+ </View>
772
+ <Text style={styles.muted} numberOfLines={1}>
773
+ {subtitle.map((part, index) => (
774
+ <Fragment key={index}>
775
+ {index ? " · " : ""}
776
+ <Text style={part.archived ? styles.struck : null}>{part.label}</Text>
777
+ </Fragment>
778
+ ))}
347
779
  </Text>
348
- {item.pinned ? <Icon name="Pin" size={12} color={theme.colors.accent} /> : null}
349
- {item.kind === "agent" ? <PermissionBadge state={agentState} live={live} theme={theme} /> : null}
350
- </View>
351
- <Text style={styles.muted} numberOfLines={1}>
352
- {subtitle.map((part, index) => (
353
- <Fragment key={index}>
354
- {index ? " · " : ""}
355
- <Text style={part.archived ? styles.struck : null}>{part.label}</Text>
356
- </Fragment>
357
- ))}
358
- </Text>
359
- </Pressable>
780
+ </Pressable>
781
+ </View>
360
782
  );
361
783
  }
362
784
 
363
785
  /**
364
- * Autosaving editor for notes and scratch. A draft (`item` null) is created on the
786
+ * Autosaving editor for notes. A draft (`item` null) is created on the
365
787
  * first non-empty save; a note that is empty when the editor closes is deleted.
366
788
  */
367
789
  function NoteEditor({
368
790
  item,
369
791
  draft,
792
+ title,
793
+ body,
794
+ onTitleChange,
795
+ onBodyChange,
370
796
  styles,
371
797
  onCreated,
372
798
  }: {
373
799
  item: Item | null;
374
800
  draft: DraftTags;
801
+ title: string;
802
+ body: string;
803
+ onTitleChange: (title: string) => void;
804
+ onBodyChange: (body: string) => void;
375
805
  styles: Styles;
376
806
  onCreated: (id: string) => void;
377
807
  }) {
378
808
  const save = useRpc(saveNote);
379
809
  const remove = useRpc(deleteItem);
380
810
  const queryClient = useQueryClient();
381
- const [title, setTitle] = useState(item?.title ?? "");
382
- const [body, setBody] = useState(item?.body ?? "");
383
811
  const [error, setError] = useState<string | null>(null);
384
812
  const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle");
385
813
 
386
- const kind = item?.kind === "scratch" ? "scratch" : "note";
387
814
  const idRef = useRef(item?.id ?? null);
388
815
  const saved = useRef({ title: item?.title ?? "", body: item?.body ?? "" });
389
816
  const latest = useRef({ title, body });
@@ -392,6 +819,16 @@ function NoteEditor({
392
819
  const onCreatedRef = useRef(onCreated);
393
820
  onCreatedRef.current = onCreated;
394
821
 
822
+ useEffect(() => {
823
+ if (!item || item.id !== idRef.current) return;
824
+ const next = syncNoteText(latest.current, saved.current, { title: item.title ?? "", body: item.body });
825
+ if (!next) return;
826
+ saved.current = next;
827
+ latest.current = next;
828
+ onTitleChange(next.title);
829
+ onBodyChange(next.body);
830
+ }, [item?.id, item?.title, item?.body]);
831
+
395
832
  /** Serialized so a draft is created once even when saves overlap. */
396
833
  const persist = (final: boolean) => {
397
834
  queue.current = queue.current.then(async () => {
@@ -405,7 +842,6 @@ function NoteEditor({
405
842
  if (t === saved.current.title && b === saved.current.body && idRef.current) return;
406
843
  const { item: next } = await save({
407
844
  ...(idRef.current ? { id: idRef.current } : draft),
408
- kind,
409
845
  title: t.trim() ? t : null,
410
846
  body: b,
411
847
  });
@@ -450,25 +886,19 @@ function NoteEditor({
450
886
  : "Saved";
451
887
 
452
888
  return (
453
- <View style={{ flex: 1, gap: 10 }}>
454
- <Field
455
- styles={styles}
456
- style={styles.input}
457
- value={title}
458
- onChangeText={setTitle}
459
- placeholder="Title (optional)"
460
- accessibilityLabel="Title"
461
- />
462
- <Field
463
- styles={styles}
464
- style={styles.editor}
465
- value={body}
466
- onChangeText={setBody}
467
- placeholder="Write something…"
468
- accessibilityLabel="Note body"
469
- multiline
470
- autoFocus={!item}
471
- />
889
+ <View style={styles.noteEditor}>
890
+ <View style={styles.noteFields}>
891
+ <Field
892
+ styles={styles}
893
+ style={styles.editor}
894
+ value={body}
895
+ onChangeText={onBodyChange}
896
+ placeholder="Write something…"
897
+ accessibilityLabel="Note body"
898
+ multiline
899
+ autoFocus={!item}
900
+ />
901
+ </View>
472
902
  <Text style={error ? styles.badge("danger") : styles.muted}>{statusText}</Text>
473
903
  </View>
474
904
  );
@@ -480,16 +910,20 @@ function ExchangeBlock({
480
910
  label,
481
911
  text,
482
912
  styles,
913
+ markdown = false,
483
914
  }: {
484
915
  label: string;
485
916
  text: string | null;
486
917
  styles: Styles;
918
+ markdown?: boolean;
487
919
  }) {
488
920
  return (
489
921
  <View style={{ gap: 2 }}>
490
922
  <Text style={styles.muted}>{label}</Text>
491
- {text ? (
492
- <Text style={styles.message} selectable>
923
+ {text && markdown ? (
924
+ <Markdown>{excerpt(text)}</Markdown>
925
+ ) : text ? (
926
+ <Text style={styles.body} selectable>
493
927
  {excerpt(text)}
494
928
  </Text>
495
929
  ) : (
@@ -529,62 +963,62 @@ function AgentExchange({
529
963
  return (
530
964
  <View style={{ gap: 12 }}>
531
965
  <ExchangeBlock label="Prompt" text={exchange.prompt} styles={styles} />
532
- <ExchangeBlock label="Agent" text={exchange.agent} styles={styles} />
966
+ <ExchangeBlock label="Agent" text={exchange.agent} styles={styles} markdown />
533
967
  </View>
534
968
  );
535
969
  }
536
970
 
537
971
  /** Open, or Unarchive once archived; sits in the Pin / Remove row. */
538
- function AgentActions({
972
+ function AgentDetailActions({
539
973
  item,
540
974
  state,
541
975
  styles,
542
976
  theme,
543
977
  navigation,
978
+ onPin,
979
+ onDelete,
544
980
  }: {
545
981
  item: Item;
546
982
  state: AgentState | undefined;
547
983
  styles: Styles;
548
984
  theme: PluginTheme;
549
985
  navigation: PluginSurfaceProps["navigation"];
986
+ onPin: () => void;
987
+ onDelete: () => void;
550
988
  }) {
551
- const unarchive = useRpc(unarchiveAgent);
552
- const queryClient = useQueryClient();
553
- const toast = useToast();
554
- const mutation = useMutation({
555
- mutationFn: () => unarchive({ agentId: item.agentId! }),
556
- onSuccess: ({ restoredWorkspace }) => {
557
- toast.show(restoredWorkspace ? "Workspace and agent restored" : "Agent unarchived", {
558
- variant: "success",
559
- });
560
- void queryClient.invalidateQueries({ queryKey: STATES_KEY });
989
+ const restore = useAgentRestore(item);
990
+ const canOpen = state === "active" && Boolean(navigation && item.agentId);
991
+ const entries = [
992
+ state === "archived" ? {
993
+ key: "unarchive",
994
+ icon: "ArchiveRestore",
995
+ label: restore.pending ? "Unarchiving" : "Unarchive",
996
+ disabled: restore.pending,
997
+ onPress: restore.restore,
998
+ } : {
999
+ key: "open",
1000
+ icon: "SquareArrowOutUpRight",
1001
+ label: canOpen ? "Open agent" : "Agent unavailable to open",
1002
+ disabled: !canOpen,
1003
+ onPress: () => {
1004
+ if (canOpen) navigation!.openAgent({ agentId: item.agentId! });
1005
+ },
561
1006
  },
562
- onError: (error) => toast.error(errorText(error)),
563
- });
564
- if (state === "archived") {
565
- return (
566
- <Button
567
- styles={styles}
568
- theme={theme}
569
- kind="primary"
570
- icon="ArchiveRestore"
571
- accessibilityLabel={mutation.isPending ? "Unarchiving" : "Unarchive"}
572
- disabled={mutation.isPending}
573
- onPress={() => mutation.mutate()}
574
- />
575
- );
576
- }
577
- if (!navigation || state === "missing" || !item.agentId) return null;
578
- return (
579
- <Button
580
- styles={styles}
581
- theme={theme}
582
- kind="primary"
583
- icon="SquareArrowOutUpRight"
584
- accessibilityLabel="Open"
585
- onPress={() => navigation.openAgent({ agentId: item.agentId! })}
586
- />
587
- );
1007
+ {
1008
+ key: "pin",
1009
+ icon: item.pinned ? "PinOff" : "Pin",
1010
+ label: item.pinned ? "Unpin" : "Pin",
1011
+ onPress: onPin,
1012
+ },
1013
+ {
1014
+ key: "delete",
1015
+ icon: "StarOff",
1016
+ label: "Remove from Inbox",
1017
+ color: theme.colors.statusDanger,
1018
+ onPress: onDelete,
1019
+ },
1020
+ ];
1021
+ return <DetailActionGroup entries={entries} styles={styles} theme={theme} />;
588
1022
  }
589
1023
 
590
1024
  function AgentDetail({
@@ -667,7 +1101,7 @@ function TagOption({
667
1101
  }
668
1102
 
669
1103
  /**
670
- * Project and workspace tags. Notes and scratch can change them; a workspace
1104
+ * Project and workspace tags. Notes can change them; a workspace
671
1105
  * must sit in the tagged project, so other projects are off while one is set.
672
1106
  * A starred agent's tags follow the agent and are read-only.
673
1107
  */
@@ -676,11 +1110,13 @@ function TagEditor({
676
1110
  archived,
677
1111
  styles,
678
1112
  theme,
1113
+ actions,
679
1114
  }: {
680
1115
  item: Item;
681
1116
  archived: Archived;
682
1117
  styles: Styles;
683
1118
  theme: PluginTheme;
1119
+ actions: ReactNode;
684
1120
  }) {
685
1121
  const options = useRpc(tagOptions);
686
1122
  const tag = useRpc(tagItem);
@@ -720,7 +1156,7 @@ function TagEditor({
720
1156
  const content = (
721
1157
  <>
722
1158
  <Icon
723
- name={isProject ? "Folder" : "GitBranch"}
1159
+ name={isProject ? "Folder" : "PanelsTopLeft"}
724
1160
  size={12}
725
1161
  color={active ? theme.colors.accentForeground : theme.colors.foregroundMuted}
726
1162
  />
@@ -756,9 +1192,12 @@ function TagEditor({
756
1192
 
757
1193
  return (
758
1194
  <View style={{ gap: 6 }}>
759
- <View style={styles.wrap}>
760
- {projectChip}
761
- {workspaceChip}
1195
+ <View style={styles.detailMeta}>
1196
+ <View style={styles.detailTags}>
1197
+ {projectChip}
1198
+ {workspaceChip}
1199
+ </View>
1200
+ {actions}
762
1201
  </View>
763
1202
  {open && optionsQuery.isPending ? <Text style={styles.muted}>Loading…</Text> : null}
764
1203
  {open && optionsQuery.isError ? (
@@ -827,6 +1266,7 @@ function Detail({
827
1266
  archived,
828
1267
  state,
829
1268
  live,
1269
+ composer,
830
1270
  styles,
831
1271
  theme,
832
1272
  navigation,
@@ -840,6 +1280,7 @@ function Detail({
840
1280
  onCreated: (id: string) => void;
841
1281
  state: AgentState | undefined;
842
1282
  live: AgentLive | undefined;
1283
+ composer: NoteComposer | undefined;
843
1284
  styles: Styles;
844
1285
  theme: PluginTheme;
845
1286
  navigation: PluginSurfaceProps["navigation"];
@@ -850,6 +1291,9 @@ function Detail({
850
1291
  const remove = useRpc(deleteItem);
851
1292
  const queryClient = useQueryClient();
852
1293
  const toast = useToast();
1294
+ const [title, setTitle] = useState(item?.title ?? "");
1295
+ const [body, setBody] = useState(item?.body ?? "");
1296
+ const actions = useNoteActions(body, composer);
853
1297
  const refresh = () => queryClient.invalidateQueries({ queryKey: LIST_KEY });
854
1298
  const run = (task: () => Promise<unknown>, after?: () => void) =>
855
1299
  task()
@@ -863,7 +1307,12 @@ function Detail({
863
1307
  <ScrollView contentContainerStyle={{ flexGrow: 1, gap: 12 }}>
864
1308
  <View style={styles.row}>
865
1309
  {onBack ? (
866
- <Pressable accessibilityRole="button" accessibilityLabel="Back" onPress={onBack}>
1310
+ <Pressable
1311
+ accessibilityRole="button"
1312
+ accessibilityLabel="Back"
1313
+ onPress={onBack}
1314
+ style={styles.detailBack}
1315
+ >
867
1316
  <Icon name="ChevronLeft" size={20} color={theme.colors.foreground} />
868
1317
  </Pressable>
869
1318
  ) : null}
@@ -872,47 +1321,79 @@ function Detail({
872
1321
  ) : (
873
1322
  <Icon name={KIND_ICON[item?.kind ?? "note"]} size={18} color={theme.colors.foregroundMuted} />
874
1323
  )}
875
- <Text style={[styles.heading, { flex: 1 }]} numberOfLines={2}>
876
- {item ? itemTitle(item) : "New note"}
877
- </Text>
1324
+ {item?.kind === "agent" ? (
1325
+ <Text style={[styles.heading, { flex: 1, minWidth: 0 }]} numberOfLines={1} ellipsizeMode="tail">
1326
+ {itemTitle(item)}
1327
+ </Text>
1328
+ ) : (
1329
+ <Field
1330
+ styles={styles}
1331
+ style={styles.detailTitleInput}
1332
+ value={title}
1333
+ onChangeText={setTitle}
1334
+ placeholder={item ? "Untitled note" : "New note"}
1335
+ accessibilityLabel="Note title"
1336
+ returnKeyType="next"
1337
+ />
1338
+ )}
878
1339
  {item?.kind === "agent" ? <PermissionBadge state={state} live={live} theme={theme} /> : null}
879
1340
  </View>
880
- {item ? (
881
- <View style={styles.wrap}>
1341
+ {item ? <TagEditor item={item} archived={archived} styles={styles} theme={theme} actions={
1342
+ <View style={styles.itemActions}>
882
1343
  {item.kind === "agent" ? (
883
- <AgentActions item={item} state={state} styles={styles} theme={theme} navigation={navigation} />
884
- ) : null}
885
- <Button
886
- styles={styles}
887
- theme={theme}
888
- icon={item.pinned ? "PinOff" : "Pin"}
889
- accessibilityLabel={item.pinned ? "Unpin" : "Pin"}
890
- onPress={() => run(() => update({ id: item.id, pinned: !item.pinned }))}
891
- />
892
- {item.kind === "scratch" ? (
893
- <Button
1344
+ <AgentDetailActions
1345
+ item={item}
1346
+ state={state}
894
1347
  styles={styles}
895
1348
  theme={theme}
896
- icon="NotebookText"
897
- label="Convert to note"
898
- onPress={() => run(() => update({ id: item.id, kind: "note" }))}
1349
+ navigation={navigation}
1350
+ onPin={() => run(() => update({ id: item.id, pinned: !item.pinned }))}
1351
+ onDelete={() => run(() => remove({ id: item.id }), onDeleted)}
899
1352
  />
900
- ) : null}
901
- <Button
902
- styles={styles}
903
- theme={theme}
904
- kind="danger"
905
- icon={item.kind === "agent" ? "StarOff" : "Trash2"}
906
- accessibilityLabel={item.kind === "agent" ? "Remove from Inbox" : "Delete"}
907
- onPress={() => run(() => remove({ id: item.id }), onDeleted)}
908
- />
1353
+ ) : (
1354
+ <DetailActionGroup
1355
+ styles={styles}
1356
+ theme={theme}
1357
+ entries={[
1358
+ {
1359
+ key: "pin",
1360
+ icon: item.pinned ? "PinOff" : "Pin",
1361
+ label: item.pinned ? "Unpin" : "Pin",
1362
+ onPress: () => run(() => update({ id: item.id, pinned: !item.pinned })),
1363
+ },
1364
+ { key: "copy", icon: "Copy", label: "Copy note", disabled: actions.copying, onPress: actions.copy },
1365
+ {
1366
+ key: "send",
1367
+ icon: "Send",
1368
+ label: actions.canSend ? "Send note to current agent" : "No current agent available",
1369
+ disabled: !actions.canSend || actions.sending,
1370
+ onPress: actions.send,
1371
+ },
1372
+ {
1373
+ key: "delete",
1374
+ icon: "Trash2",
1375
+ label: "Delete",
1376
+ color: theme.colors.statusDanger,
1377
+ onPress: () => run(() => remove({ id: item.id }), onDeleted),
1378
+ },
1379
+ ]}
1380
+ />
1381
+ )}
909
1382
  </View>
910
- ) : null}
911
- {item ? <TagEditor item={item} archived={archived} styles={styles} theme={theme} /> : null}
1383
+ } /> : null}
912
1384
  {item?.kind === "agent" ? (
913
1385
  <AgentDetail item={item} state={state} live={live} styles={styles} />
914
1386
  ) : (
915
- <NoteEditor item={item} draft={draft} styles={styles} onCreated={onCreated} />
1387
+ <NoteEditor
1388
+ item={item}
1389
+ draft={draft}
1390
+ title={title}
1391
+ body={body}
1392
+ onTitleChange={setTitle}
1393
+ onBodyChange={setBody}
1394
+ styles={styles}
1395
+ onCreated={onCreated}
1396
+ />
916
1397
  )}
917
1398
  </ScrollView>
918
1399
  );
@@ -975,55 +1456,6 @@ function AgentPicker({
975
1456
  );
976
1457
  }
977
1458
 
978
- function Chip({
979
- label,
980
- icon,
981
- accessibilityLabel,
982
- active,
983
- struck,
984
- styles,
985
- theme,
986
- onPress,
987
- }: {
988
- label: string;
989
- icon?: string;
990
- accessibilityLabel: string;
991
- active: boolean;
992
- /** Archived project / workspace. */
993
- struck?: boolean;
994
- styles: Styles;
995
- theme: PluginTheme;
996
- onPress: () => void;
997
- }) {
998
- const color = active ? theme.colors.accentForeground : theme.colors.foregroundMuted;
999
- return (
1000
- <Pressable
1001
- accessibilityRole="button"
1002
- accessibilityLabel={accessibilityLabel}
1003
- onPress={onPress}
1004
- style={styles.chip(active)}
1005
- >
1006
- {icon ? <Icon name={icon} size={12} color={color} /> : null}
1007
- <Text style={[styles.chipText(active), struck ? styles.struck : null]}>{label}</Text>
1008
- </Pressable>
1009
- );
1010
- }
1011
-
1012
- /** A single-line chip row; on web the mouse wheel scrolls it sideways. */
1013
- function ChipStrip({ styles, children }: { styles: Styles; children: ReactNode }) {
1014
- const scrollRef = useRef<ComponentRef<typeof ScrollView>>(null);
1015
- useEffect(() => {
1016
- if (Platform.OS !== "web") return;
1017
- const node = scrollRef.current?.getScrollableNode() as HorizontalScrollNode | null | undefined;
1018
- return node ? wheelScrollsHorizontally(node) : undefined;
1019
- }, []);
1020
- return (
1021
- <ScrollView ref={scrollRef} horizontal showsHorizontalScrollIndicator={false}>
1022
- <View style={styles.row}>{children}</View>
1023
- </ScrollView>
1024
- );
1025
- }
1026
-
1027
1459
  /**
1028
1460
  * The Inbox list and editor. Without `workspace` it is the global page (every
1029
1461
  * visible item, workspace filter, ⌘K selection requests); with it, the list is
@@ -1036,20 +1468,29 @@ export function InboxView({
1036
1468
  workspace,
1037
1469
  }: Pick<PluginSurfaceProps, "theme" | "layout" | "navigation"> & { workspace?: InboxWorkspace }) {
1038
1470
  const compact = workspace ? true : layout.compact;
1039
- const styles = useMemo(() => createStyles(theme, compact), [theme, compact]);
1471
+ const styles = useMemo(() => createStyles(theme, compact, Boolean(workspace)), [theme, compact, workspace]);
1040
1472
  const list = useRpc(listItems);
1041
1473
  const states = useRpc(agentStates);
1042
1474
  const queryClient = useQueryClient();
1475
+ const [composer] = useComposers({ focused: true });
1043
1476
 
1044
1477
  const filters = useInboxFilters();
1045
1478
  const updateFilters = useRef(filters.update);
1046
1479
  updateFilters.current = filters.update;
1047
1480
  const shown = filters.values ? visibleInboxFilters(filters.values, { workspaceId: workspace?.id }) : null;
1048
- const kind = shown?.kind ?? null;
1049
- const projectKey = shown?.projectKey ?? null;
1050
- const scope = shown?.workspaceId ?? null;
1481
+ const kinds = shown?.kinds ?? [];
1482
+ const projectKeys = shown?.projectKeys ?? [];
1483
+ const scope = shown?.workspaceIds ?? [];
1051
1484
  const [query, setQuery] = useState("");
1485
+ const [searchOpen, setSearchOpen] = useState(false);
1486
+ const [searchSlotWidth, setSearchSlotWidth] = useState(0);
1487
+ const searchProgress = useRef(new Animated.Value(0)).current;
1488
+ const searchInputRef = useRef<{ focus?: () => void } | null>(null);
1052
1489
  const [picking, setPicking] = useState(false);
1490
+ const [filterMenuOpen, setFilterMenuOpen] = useState(false);
1491
+ const filterTriggerRef = useRef<View>(null);
1492
+ const listChromeRef = useRef<View>(null);
1493
+ const [filterMenuAnchor, setFilterMenuAnchor] = useState<{ top: number; right: number } | null>(null);
1053
1494
  const sort = filters.values ? inboxListSort(filters.values, { workspaceId: workspace?.id }) : "updated";
1054
1495
  const [listWidth, setListWidth] = useState(rememberedListWidth);
1055
1496
  const widthAtGrant = useRef(listWidth);
@@ -1089,13 +1530,51 @@ export function InboxView({
1089
1530
  const selectedId = selection?.id ?? null;
1090
1531
  const select = (id: string | null) => setSelection(id ? { id, draft: null, session: nextSession() } : null);
1091
1532
 
1533
+ useEffect(() => {
1534
+ searchProgress.stopAnimation();
1535
+ searchProgress.setValue(0);
1536
+ setSearchOpen(false);
1537
+ setQuery("");
1538
+ }, [workspace?.id, searchProgress]);
1539
+
1540
+ useEffect(() => {
1541
+ if (!searchOpen) return;
1542
+ const id = setTimeout(() => searchInputRef.current?.focus?.(), SEARCH_ANIM_MS);
1543
+ return () => clearTimeout(id);
1544
+ }, [searchOpen]);
1545
+
1546
+ function openSearch() {
1547
+ if (searchOpen) return;
1548
+ setSearchOpen(true);
1549
+ Animated.timing(searchProgress, {
1550
+ toValue: 1,
1551
+ duration: SEARCH_ANIM_MS,
1552
+ easing: Easing.out(Easing.cubic),
1553
+ useNativeDriver: false,
1554
+ }).start();
1555
+ }
1556
+
1557
+ function closeSearch() {
1558
+ if (!searchOpen) return;
1559
+ Animated.timing(searchProgress, {
1560
+ toValue: 0,
1561
+ duration: SEARCH_CLOSE_ANIM_MS,
1562
+ easing: Easing.out(Easing.cubic),
1563
+ useNativeDriver: false,
1564
+ }).start(({ finished }) => {
1565
+ if (!finished) return;
1566
+ setSearchOpen(false);
1567
+ setQuery("");
1568
+ });
1569
+ }
1570
+
1092
1571
  // A command can request a selection while the surface is already mounted.
1093
1572
  useEffect(() => {
1094
1573
  if (workspace) return;
1095
1574
  return onSelectionRequest(() => {
1096
1575
  const next = toSelection(takeSelection());
1097
1576
  if (!next) return;
1098
- updateFilters.current({ kind: "all", projectKey: null, workspaceId: null });
1577
+ updateFilters.current({ kinds: ["agent", "note"], projectKeys: [], workspaceIds: [] });
1099
1578
  setQuery("");
1100
1579
  setSelection(next);
1101
1580
  void queryClient.invalidateQueries({ queryKey: LIST_KEY });
@@ -1105,17 +1584,16 @@ export function InboxView({
1105
1584
  useEffect(
1106
1585
  () =>
1107
1586
  onItemsChanged(() => {
1108
- void queryClient.invalidateQueries({ queryKey: LIST_KEY });
1109
- void queryClient.invalidateQueries({ queryKey: CANDIDATES_KEY });
1587
+ void queryClient.invalidateQueries({ queryKey: ["inbox"] });
1110
1588
  }),
1111
1589
  [queryClient],
1112
1590
  );
1113
1591
 
1114
1592
  const filter = shown
1115
1593
  ? {
1116
- ...(shown.kind === "all" ? {} : { kind: shown.kind }),
1117
- ...(shown.projectKey ? { projectKey: shown.projectKey } : {}),
1118
- ...(workspace ? { inboxOf: workspace.id } : shown.workspaceId ? { workspaceId: shown.workspaceId } : {}),
1594
+ kinds: shown.kinds,
1595
+ projectKeys: shown.projectKeys,
1596
+ ...(workspace ? { inboxOf: workspace.id } : { workspaceIds: shown.workspaceIds }),
1119
1597
  ...(query.trim() ? { query: query.trim() } : {}),
1120
1598
  ...(sort === "updated" ? {} : { sort }),
1121
1599
  }
@@ -1130,6 +1608,16 @@ export function InboxView({
1130
1608
  const items = itemsQuery.data?.items ?? [];
1131
1609
  const projects = itemsQuery.data?.projects ?? [];
1132
1610
  const workspaces = itemsQuery.data?.workspaces ?? [];
1611
+ useEffect(() => {
1612
+ if (shouldSelectFirstItem({
1613
+ globalSurface: !workspace,
1614
+ selection,
1615
+ firstItemId: items[0]?.id,
1616
+ isPlaceholderData: itemsQuery.isPlaceholderData,
1617
+ })) {
1618
+ setSelection({ id: items[0]!.id, draft: null, session: nextSession() });
1619
+ }
1620
+ }, [items, itemsQuery.isPlaceholderData, selection, workspace]);
1133
1621
  const archivedData = itemsQuery.data?.archived;
1134
1622
  const archived = useMemo<Archived>(
1135
1623
  () => ({ projects: new Set(archivedData?.projects), workspaces: new Set(archivedData?.workspaces) }),
@@ -1140,14 +1628,12 @@ export function InboxView({
1140
1628
  useEffect(() => {
1141
1629
  const current = filters.values;
1142
1630
  if (workspace || !itemsQuery.data || itemsQuery.isPlaceholderData || !current) return;
1143
- const staleProject =
1144
- current.projectKey && !itemsQuery.data.projects.some((entry) => entry.key === current.projectKey);
1145
- const staleWorkspace =
1146
- current.workspaceId && !itemsQuery.data.workspaces.some((entry) => entry.id === current.workspaceId);
1147
- if (staleProject || staleWorkspace) {
1631
+ const projectKeys = current.projectKeys.filter((key) => itemsQuery.data!.projects.some((entry) => entry.key === key));
1632
+ const workspaceIds = current.workspaceIds.filter((id) => itemsQuery.data!.workspaces.some((entry) => entry.id === id));
1633
+ if (projectKeys.length !== current.projectKeys.length || workspaceIds.length !== current.workspaceIds.length) {
1148
1634
  updateFilters.current({
1149
- ...(staleProject ? { projectKey: null } : {}),
1150
- ...(staleWorkspace ? { workspaceId: null } : {}),
1635
+ ...(projectKeys.length !== current.projectKeys.length ? { projectKeys } : {}),
1636
+ ...(workspaceIds.length !== current.workspaceIds.length ? { workspaceIds } : {}),
1151
1637
  });
1152
1638
  }
1153
1639
  }, [filters.values, itemsQuery.data, itemsQuery.isPlaceholderData, workspace]);
@@ -1159,13 +1645,12 @@ export function InboxView({
1159
1645
  enabled: agentIds.length > 0,
1160
1646
  refetchInterval: 10_000,
1161
1647
  });
1162
- useEffect(() => {
1163
- if (statesQuery.data?.titlesChanged) notifyItemsChanged();
1164
- }, [statesQuery.data]);
1165
1648
  const agentState = (item: Item) =>
1166
1649
  item.agentId ? statesQuery.data?.states[item.agentId] : undefined;
1167
1650
  const agentLive = (item: Item) =>
1168
1651
  item.agentId ? statesQuery.data?.live?.[item.agentId] : undefined;
1652
+ const agentUpdatedAt = (item: Item) =>
1653
+ item.agentId ? statesQuery.data?.lastActivityAt?.[item.agentId] : undefined;
1169
1654
 
1170
1655
  const selected = items.find((item) => item.id === selectedId) ?? null;
1171
1656
  // A draft, or a note just created from one, stays open while the list catches up.
@@ -1174,56 +1659,129 @@ export function InboxView({
1174
1659
  const showDetail = !compact || Boolean(editing);
1175
1660
 
1176
1661
  const createNote = () => {
1177
- filters.update(workspace ? { panelKind: "all" } : { kind: "all", projectKey: null, workspaceId: null });
1662
+ filters.update(workspace
1663
+ ? { panelKinds: ["agent", "note"] }
1664
+ : { kinds: ["agent", "note"], projectKeys: [], workspaceIds: [] });
1178
1665
  setSelection({ id: null, draft: workspace ? { workspaceId: workspace.id } : {}, session: nextSession() });
1179
1666
  };
1180
1667
 
1181
1668
  const noteButton = (
1182
- <Button
1669
+ <ToolbarIconButton
1183
1670
  styles={styles}
1184
1671
  theme={theme}
1185
- kind="primary"
1186
- icon="NotebookPen"
1672
+ icon="FilePlus2"
1187
1673
  accessibilityLabel="New note"
1188
1674
  onPress={createNote}
1189
1675
  />
1190
1676
  );
1191
1677
 
1678
+ useEffect(() => {
1679
+ if (!filterMenuOpen) {
1680
+ setFilterMenuAnchor(null);
1681
+ return;
1682
+ }
1683
+ const trigger = filterTriggerRef.current;
1684
+ const root = listChromeRef.current;
1685
+ if (!trigger || !root) return;
1686
+ trigger.measureInWindow((left, top, width, height) => {
1687
+ root.measureInWindow((rootLeft, rootTop, rootWidth) => {
1688
+ setFilterMenuAnchor({ top: top + height - rootTop + 4, right: rootLeft + rootWidth - (left + width) });
1689
+ });
1690
+ });
1691
+ }, [filterMenuOpen]);
1692
+
1192
1693
  return (
1193
1694
  <View style={styles.screen}>
1194
1695
  {showList ? (
1195
- <View style={[styles.listPane, compact ? { flex: 1 } : { width: listWidth }]}>
1696
+ <View
1697
+ ref={listChromeRef}
1698
+ style={[styles.listPane, styles.listChrome, compact ? { flex: 1 } : { width: listWidth }]}
1699
+ >
1196
1700
  <View style={styles.toolbar}>
1197
- <View style={styles.row}>
1198
- <Field
1199
- styles={styles}
1200
- style={[styles.input, { flex: 1, minWidth: 0 }]}
1201
- value={query}
1202
- onChangeText={setQuery}
1203
- placeholder="Search"
1204
- accessibilityLabel="Search Inbox"
1205
- />
1206
- {noteButton}
1207
- {workspace ? (
1208
- <Button
1209
- styles={styles}
1210
- theme={theme}
1211
- icon={picking ? "X" : "Star"}
1212
- accessibilityLabel={picking ? "Done" : "Add agent"}
1213
- onPress={() => setPicking((open) => !open)}
1214
- />
1215
- ) : (
1216
- <Button
1701
+ <View style={styles.toolbarRow}>
1702
+ <View
1703
+ style={styles.toolbarSearchSlot}
1704
+ onLayout={(event) => {
1705
+ const next = event.nativeEvent.layout.width;
1706
+ setSearchSlotWidth((current) => (current === next ? current : next));
1707
+ }}
1708
+ >
1709
+ <Animated.View
1710
+ pointerEvents={searchOpen ? "auto" : "none"}
1711
+ style={[
1712
+ styles.toolbarSearchField,
1713
+ {
1714
+ width: searchProgress.interpolate({
1715
+ inputRange: [0, 1],
1716
+ outputRange: [0, Math.max(0, searchSlotWidth - 8)],
1717
+ }),
1718
+ opacity: searchProgress,
1719
+ marginLeft: searchProgress.interpolate({
1720
+ inputRange: [0, 1],
1721
+ outputRange: [0, 8],
1722
+ }),
1723
+ },
1724
+ ]}
1725
+ >
1726
+ <Icon name="Search" size={14} color={theme.colors.foregroundMuted} />
1727
+ <TextInput
1728
+ ref={searchInputRef as never}
1729
+ value={query}
1730
+ onChangeText={setQuery}
1731
+ placeholder="Search"
1732
+ placeholderTextColor={theme.colors.foregroundMuted}
1733
+ autoCapitalize="none"
1734
+ autoCorrect={false}
1735
+ returnKeyType="search"
1736
+ editable={searchOpen}
1737
+ style={styles.toolbarSearchInput}
1738
+ accessibilityLabel="Search Inbox"
1739
+ />
1740
+ </Animated.View>
1741
+ </View>
1742
+ <View style={styles.toolbarActions}>
1743
+ <ToolbarIconButton
1217
1744
  styles={styles}
1218
1745
  theme={theme}
1219
- icon={SORTS.find((option) => option.id === sort)!.icon}
1220
- accessibilityLabel={`Sort: ${SORTS.find((option) => option.id === sort)!.label}`}
1746
+ icon={searchOpen ? "X" : "Search"}
1747
+ accessibilityLabel={searchOpen ? "Close search" : "Search Inbox"}
1748
+ active={searchOpen}
1221
1749
  onPress={() => {
1222
- const index = SORTS.findIndex((option) => option.id === sort);
1223
- filters.update({ sort: SORTS[(index + 1) % SORTS.length]!.id });
1750
+ if (searchOpen) closeSearch();
1751
+ else openSearch();
1224
1752
  }}
1225
1753
  />
1226
- )}
1754
+ <View ref={filterTriggerRef} collapsable={false}>
1755
+ <KindFilterMenu
1756
+ value={kinds}
1757
+ theme={theme}
1758
+ open={filterMenuOpen}
1759
+ onOpenChange={setFilterMenuOpen}
1760
+ />
1761
+ </View>
1762
+ {noteButton}
1763
+ {workspace ? (
1764
+ <ToolbarIconButton
1765
+ styles={styles}
1766
+ theme={theme}
1767
+ icon={picking ? "X" : "Star"}
1768
+ accessibilityLabel={picking ? "Done" : "Add agent"}
1769
+ active={picking}
1770
+ onPress={() => setPicking((open) => !open)}
1771
+ />
1772
+ ) : (
1773
+ <ToolbarIconButton
1774
+ styles={styles}
1775
+ theme={theme}
1776
+ icon={SORTS.find((option) => option.id === sort)!.icon}
1777
+ accessibilityLabel={`Sort: ${SORTS.find((option) => option.id === sort)!.label}`}
1778
+ onPress={() => {
1779
+ const index = SORTS.findIndex((option) => option.id === sort);
1780
+ filters.update({ sort: SORTS[(index + 1) % SORTS.length]!.id });
1781
+ }}
1782
+ />
1783
+ )}
1784
+ </View>
1227
1785
  </View>
1228
1786
  {workspace && picking ? (
1229
1787
  <AgentPicker
@@ -1232,67 +1790,13 @@ export function InboxView({
1232
1790
  theme={theme}
1233
1791
  onStarred={() => {
1234
1792
  setPicking(false);
1235
- filters.update({ panelKind: "all" });
1793
+ filters.update({ panelKinds: ["agent", "note"] });
1236
1794
  setQuery("");
1237
1795
  }}
1238
1796
  />
1239
1797
  ) : null}
1240
- <View style={styles.wrap}>
1241
- {FILTERS.map((option) => (
1242
- <Chip
1243
- key={option.id}
1244
- label={option.label}
1245
- accessibilityLabel={`Show ${option.label}`}
1246
- active={kind === option.id}
1247
- styles={styles}
1248
- theme={theme}
1249
- onPress={() => filters.update(workspace ? { panelKind: option.id } : { kind: option.id })}
1250
- />
1251
- ))}
1252
- </View>
1253
- {!workspace && projects.length > 0 ? (
1254
- <ChipStrip styles={styles}>
1255
- {projects.map((project) => {
1256
- const active = projectKey === project.key;
1257
- return (
1258
- <Chip
1259
- key={project.key}
1260
- icon="Folder"
1261
- label={`${project.label} · ${project.count}`}
1262
- accessibilityLabel={`Filter by project ${project.label}${project.archived ? " (archived)" : ""}`}
1263
- active={active}
1264
- struck={project.archived}
1265
- styles={styles}
1266
- theme={theme}
1267
- onPress={() => filters.update({ projectKey: active ? null : project.key })}
1268
- />
1269
- );
1270
- })}
1271
- </ChipStrip>
1272
- ) : null}
1273
- {!workspace && workspaces.length > 0 ? (
1274
- <ChipStrip styles={styles}>
1275
- {workspaces.map((entry) => (
1276
- <Chip
1277
- key={entry.id}
1278
- icon="GitBranch"
1279
- label={`${entry.label} · ${entry.count}`}
1280
- accessibilityLabel={`Filter by workspace ${entry.label}${entry.archived ? " (archived)" : ""}`}
1281
- active={scope === entry.id}
1282
- struck={entry.archived}
1283
- styles={styles}
1284
- theme={theme}
1285
- onPress={() =>
1286
- filters.update({
1287
- workspaceId: filters.values?.workspaceId === entry.id ? null : entry.id,
1288
- })
1289
- }
1290
- />
1291
- ))}
1292
- </ChipStrip>
1293
- ) : null}
1294
1798
  </View>
1295
- <ScrollView style={{ flex: 1 }}>
1799
+ <ScrollView style={{ flex: 1 }} scrollEnabled={!filterMenuOpen}>
1296
1800
  {itemsQuery.isError ? (
1297
1801
  <View style={styles.empty}>
1298
1802
  <Text style={styles.badge("danger")}>{errorText(itemsQuery.error)}</Text>
@@ -1308,21 +1812,53 @@ export function InboxView({
1308
1812
  </View>
1309
1813
  ) : (
1310
1814
  items.map((item) => (
1311
- <ItemRow
1312
- key={item.id}
1313
- item={item}
1314
- selected={item.id === selectedId}
1315
- state={agentState(item)}
1316
- live={agentLive(item)}
1317
- archived={archived}
1318
- hideWorkspaceId={workspace?.id ?? null}
1319
- styles={styles}
1320
- theme={theme}
1321
- onPress={() => select(item.id)}
1322
- />
1815
+ <Fragment key={item.id}>
1816
+ <ItemRow
1817
+ item={item}
1818
+ selected={item.id === selectedId}
1819
+ state={agentState(item)}
1820
+ live={agentLive(item)}
1821
+ agentUpdatedAt={agentUpdatedAt(item)}
1822
+ archived={archived}
1823
+ hideWorkspaceId={workspace?.id ?? null}
1824
+ composer={composer}
1825
+ navigation={navigation}
1826
+ styles={styles}
1827
+ theme={theme}
1828
+ onPress={() => select(item.id)}
1829
+ onDeleted={() => select(null)}
1830
+ />
1831
+ <View style={styles.itemDivider} />
1832
+ </Fragment>
1323
1833
  ))
1324
1834
  )}
1325
1835
  </ScrollView>
1836
+ {filterMenuOpen ? (
1837
+ <Pressable
1838
+ accessibilityRole="button"
1839
+ accessibilityLabel="Close filter"
1840
+ onPress={() => setFilterMenuOpen(false)}
1841
+ style={styles.filterMenuBackdrop}
1842
+ />
1843
+ ) : null}
1844
+ {filterMenuOpen && filterMenuAnchor ? (
1845
+ <View style={[styles.filterMenuPosition, filterMenuAnchor]}>
1846
+ <KindFilterMenuPanel
1847
+ value={kinds}
1848
+ projects={workspace ? undefined : projects}
1849
+ projectKeys={projectKeys}
1850
+ onProjectChange={workspace ? undefined : (key) => filters.update({ projectKeys: toggleInboxSelection(projectKeys, key) })}
1851
+ workspaces={workspace ? undefined : workspaces}
1852
+ workspaceIds={scope}
1853
+ onWorkspaceChange={workspace ? undefined : (id) => filters.update({ workspaceIds: toggleInboxSelection(scope, id) })}
1854
+ theme={theme}
1855
+ onChange={(next) => {
1856
+ const selected = toggleInboxKind(kinds, next);
1857
+ filters.update(workspace ? { panelKinds: selected } : { kinds: selected, projectKeys: [], workspaceIds: [] });
1858
+ }}
1859
+ />
1860
+ </View>
1861
+ ) : null}
1326
1862
  </View>
1327
1863
  ) : null}
1328
1864
  {showList && showDetail ? (
@@ -1340,6 +1876,7 @@ export function InboxView({
1340
1876
  archived={archived}
1341
1877
  state={selected ? agentState(selected) : undefined}
1342
1878
  live={selected ? agentLive(selected) : undefined}
1879
+ composer={composer}
1343
1880
  styles={styles}
1344
1881
  theme={theme}
1345
1882
  navigation={navigation}