paseo-follow-up 2.4.0-beta.4 → 2.4.0-beta.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 (61) hide show
  1. package/client/brief.tsx +30 -11
  2. package/client/catch-up.tsx +15 -7
  3. package/client/compass-settings.tsx +323 -0
  4. package/client/home-chrome.tsx +16 -2
  5. package/client/home-view.ts +2 -1
  6. package/client/home.tsx +41 -12
  7. package/client/image-attach.tsx +276 -0
  8. package/client/more-context.tsx +18 -11
  9. package/client/morning-brief-settings.tsx +2 -0
  10. package/client/new.tsx +34 -16
  11. package/client/pending-answers.ts +25 -5
  12. package/client/pr-stats-settings.tsx +35 -10
  13. package/client/questions.tsx +15 -10
  14. package/client/row-actions.ts +0 -1
  15. package/client/unsent-images.ts +26 -0
  16. package/index.server.ts +89 -13
  17. package/package.json +3 -1
  18. package/server/agent-actions.ts +25 -10
  19. package/server/agent-hook.mjs +1 -1
  20. package/server/agent-parity.ts +24 -6
  21. package/server/compass.ts +320 -0
  22. package/server/daemon.ts +6 -2
  23. package/server/dispatch.ts +45 -12
  24. package/server/engine.ts +77 -13
  25. package/server/hook-source.ts +1 -1
  26. package/server/image-store.ts +100 -0
  27. package/server/image-support.ts +37 -0
  28. package/server/inbox.ts +4 -3
  29. package/server/mcp-source.ts +18 -11
  30. package/server/mcp.mjs +18 -11
  31. package/server/message-queue.ts +26 -5
  32. package/server/overseer-prompt-source.ts +1 -1
  33. package/server/overseer-prompt.md +1 -1
  34. package/server/overseer.ts +71 -23
  35. package/server/pr-stats-gate.ts +48 -10
  36. package/server/pr-stats-sync.ts +7 -7
  37. package/server/pr-stats.ts +17 -12
  38. package/server/ranker.ts +5 -1
  39. package/server/report-issue-adapter.ts +1 -1
  40. package/server/tasks.ts +8 -3
  41. package/shared/activity.ts +6 -0
  42. package/shared/agent-load.ts +6 -1
  43. package/shared/attention.ts +5 -4
  44. package/shared/brief-sources.ts +3 -0
  45. package/shared/chat.ts +1 -1
  46. package/shared/compass.ts +690 -0
  47. package/shared/contracts.ts +17 -4
  48. package/shared/dispatch.ts +40 -10
  49. package/shared/images.ts +95 -0
  50. package/shared/model.ts +21 -2
  51. package/shared/morning-brief.ts +4 -1
  52. package/shared/overseer.ts +151 -11
  53. package/shared/pr-stats-settings.ts +27 -0
  54. package/shared/priorities.ts +2 -2
  55. package/shared/queue.ts +3 -0
  56. package/shared/ranker.ts +7 -3
  57. package/shared/row-menu.ts +1 -5
  58. package/shared/send-decision.ts +68 -4
  59. package/shared/status-invariants.ts +18 -0
  60. package/shared/status.ts +1 -1
  61. package/shared/task-rows.ts +5 -3
package/client/brief.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useMemo, useState, useSyncExternalStore } from "react";
1
+ import { useMemo, useState, useSyncExternalStore, type ReactNode } from "react";
2
2
  import { browserKey, liveBriefKey, LIVE_BRIEF_POLL_MS, workspaceKey } from "./keys";
3
3
  import { Platform, View, useWindowDimensions } from "react-native";
4
4
  import { Pressable, Text } from "./text";
@@ -14,6 +14,7 @@ import { briefKey, HEADLINE_WORD } from "../shared/headline";
14
14
  /** The card's kind word comes from the same table as the pill and the Needs-you row. */
15
15
  const word = (kind: Brief["kind"]) => HEADLINE_WORD[briefKey(kind)];
16
16
  import { answerQuestionRpc, briefActionRpc, browserStatusRpc, inboxBriefRpc } from "../shared/contracts";
17
+ import { ImageField, useImageAttachments, type ImageAttachments } from "./image-attach";
17
18
  import { errorText, mootNote } from "../shared/errors";
18
19
  import { PRIMARY_FORM } from "./dock";
19
20
  import { OTHER, OTHER_LABEL, OWN_ANSWER_HINT, briefAnswerStatus, isDoneOnly, isOpen, isOther, TASK_DONE, type Question } from "../shared/questions";
@@ -145,6 +146,11 @@ function OptionRow({ option, recommended, sending, disabled, tight, open, onTogg
145
146
  }
146
147
 
147
148
  /** "Add note" / "Remove note": a quiet text link (muted, 13px), 44 tall on phones. QuestionBody uses it too. */
149
+ /** The brief's answer or note field with the card's pasted images (client/image-attach.tsx); a read-only copy has none. */
150
+ /** `row`: whether this field draws the card's thumbnails. One set per card, so only its last open field does. */
151
+ function WithImages({ img, c, compact, row, children }: { img?: ImageAttachments; c: Colors; compact: boolean; row: boolean; children: ReactNode }) {
152
+ return img ? <ImageField model={img} theme={{ colors: c }} compact={compact} row={row}>{children}</ImageField> : <>{children}</>;
153
+ }
148
154
  export function NoteLink({ icon, label, a11y, disabled, onPress, c, compact }: { icon: string; label: string; a11y: string; disabled: boolean; onPress: () => void; c: Colors; compact: boolean }) {
149
155
  return <Pressable accessibilityRole="button" accessibilityLabel={a11y} accessibilityState={{ disabled }} disabled={disabled} onPress={onPress} hitSlop={6}
150
156
  style={({ hovered, pressed, focused }: { hovered?: boolean; pressed: boolean; focused?: boolean }) => ({ ...ring(focused, c), flexDirection: "row", alignItems: "center", gap: 6, alignSelf: "flex-start", minHeight: compact ? 44 : 28, paddingHorizontal: 4, marginLeft: -4, borderRadius: 6, opacity: disabled ? 0.5 : pressed ? 0.7 : 1, backgroundColor: hovered && !disabled ? withAlpha(c.foreground, 0.05) : "transparent" })}>
@@ -157,7 +163,9 @@ export function NoteLink({ icon, label, a11y, disabled, onPress, c, compact }: {
157
163
  * The card's body: decisions, error text, details, context, facts and links, and the agent's extra ask. Shared by the
158
164
  * open card and by a past card's read-only "Show full question", so a past question reads exactly as it was asked.
159
165
  */
160
- function BriefBody({ b, c, compact, tight, embedded, height, mode, picks, onPick, busy, onSend, words = {}, onWords, onSendOther, notes = {}, notesOpen = {}, onNote, onNoteOpen, doneIds = [] }: {
166
+ export function BriefBody({ b, c, compact, tight, embedded, height, mode, picks, onPick, busy, onSend, words = {}, onWords, onSendOther, notes = {}, notesOpen = {}, onNote, onNoteOpen, doneIds = [], img }: {
167
+ /** The card's pasted images (one model for its answer and note fields). Absent: read-only copies. */
168
+ img?: ImageAttachments;
161
169
  /** one-done-button: decisions answered by the card's Done button (an action card), drawn without option rows. */
162
170
  doneIds?: readonly string[];
163
171
  b: Brief; c: Colors; compact: boolean; tight: boolean; embedded: boolean; height: number;
@@ -179,6 +187,9 @@ function BriefBody({ b, c, compact, tight, embedded, height, mode, picks, onPick
179
187
  const extra = !!b.context || b.facts.length > 0 || b.links.length > 0;
180
188
  const showExtra = readonly || !tight || details || extrasFit(b, height);
181
189
  const numbered = b.decisions.length > 1;
190
+ // The card has one image set (its answer and note fields share it), so its thumbnails are drawn once: under the
191
+ // last decision whose answer or note field is open. Several open fields each drew them before.
192
+ const rowAt = readonly ? null : [...b.decisions].reverse().find(d => isOther(picks[d.id]) || !!notesOpen[d.id])?.id ?? null;
182
193
  return <>
183
194
  {b.decisions.map((d, i) => { const done = !readonly && doneIds.includes(d.id); return <View key={d.id} accessibilityRole={mode === "select" ? "radiogroup" : undefined} accessibilityLabel={mode === "select" ? d.question : undefined} style={{ gap: 8 }}>
184
195
  {(numbered || d.question.trim() !== b.ask.trim()) && <RichText style={{ color: c.foreground, fontSize: 14, lineHeight: 20, fontWeight: numbered ? "600" : "400" }}>{`${numbered ? `${i + 1}. ` : ""}${d.question}`}</RichText>}
@@ -193,20 +204,20 @@ function BriefBody({ b, c, compact, tight, embedded, height, mode, picks, onPick
193
204
  onPress={() => onPick(d.id, OTHER)} c={c} compact={compact} />}
194
205
  {/* Something else's field with its Send answer, kept on screen together while typing (DockedPane). */}
195
206
  {!readonly && isOther(picks[d.id]) && <View {...PRIMARY_FORM} style={{ gap: 8 }}>
196
- <TextInput accessibilityLabel={`Your answer${numbered ? ` to question ${i + 1}` : ""}, required`} placeholder="Your answer (required)" placeholderTextColor={c.foregroundMuted} autoFocus multiline maxLength={2000}
207
+ <WithImages img={img} c={c} compact={compact} row={rowAt === d.id}><TextInput accessibilityLabel={`Your answer${numbered ? ` to question ${i + 1}` : ""}, required`} placeholder="Your answer (required)" placeholderTextColor={c.foregroundMuted} autoFocus multiline maxLength={2000}
197
208
  value={words[d.id] ?? ""} editable={!busy} onChangeText={t => onWords?.(d.id, t)}
198
- style={{ minHeight: compact ? 66 : 58, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 8, borderWidth: 1, borderColor: words[d.id]?.trim() ? c.border : withAlpha(c.accent, 0.7), color: c.foreground, backgroundColor: c.surface0, fontSize: 14, lineHeight: 20, textAlignVertical: "top" }} />
209
+ style={{ minHeight: compact ? 66 : 58, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 8, borderWidth: 1, borderColor: words[d.id]?.trim() ? c.border : withAlpha(c.accent, 0.7), color: c.foreground, backgroundColor: c.surface0, fontSize: 14, lineHeight: 20, textAlignVertical: "top" }} /></WithImages>
199
210
  {mode === "send" && <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 10 }}>
200
- <Btn shortcut label={busy === `${d.id}:${OTHER}` ? "Sending…" : "Send answer"} icon="Send" primary disabled={!words[d.id]?.trim() || !!busy} onPress={() => onSendOther?.(d.id)} c={c} compact={compact} />
211
+ <Btn shortcut label={busy === `${d.id}:${OTHER}` ? "Sending…" : "Send answer"} icon="Send" primary disabled={!words[d.id]?.trim() || !!busy || !!img?.blocked} onPress={() => onSendOther?.(d.id)} c={c} compact={compact} />
201
212
  {!words[d.id]?.trim() && <Text style={{ flexShrink: 1, color: c.foregroundMuted, fontSize: 12, lineHeight: 16 }}>{OWN_ANSWER_HINT}</Text>}
202
213
  </View>}
203
214
  </View>}
204
215
  {/* A note on a lettered pick ("A, but…"): quiet until asked for, never in the way of the one-tap answer. */}
205
216
  {!readonly && !isOther(picks[d.id]) && (notesOpen[d.id] ? <View {...PRIMARY_FORM} style={{ gap: 6, marginTop: 2 }}>
206
217
  <Text style={{ color: c.foregroundMuted, fontSize: 12, lineHeight: 16, fontWeight: "600" }}>Note</Text>
207
- <TextInput accessibilityLabel={`Note for the agent${numbered ? ` on decision ${i + 1}` : ""}, optional`} placeholder={mode === "select" ? "Sent with your pick for this decision" : "Sent with the option you tap"}
218
+ <WithImages img={img} c={c} compact={compact} row={rowAt === d.id}><TextInput accessibilityLabel={`Note for the agent${numbered ? ` on decision ${i + 1}` : ""}, optional`} placeholder={mode === "select" ? "Sent with your pick for this decision" : "Sent with the option you tap"}
208
219
  placeholderTextColor={c.foregroundMuted} autoFocus={focusNote === d.id} multiline maxLength={2000} value={notes[d.id] ?? ""} editable={!busy} onChangeText={t => onNote?.(d.id, t)}
209
- style={{ minHeight: compact ? 66 : 58, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 8, borderWidth: 1, borderColor: c.border, color: c.foreground, backgroundColor: c.surface0, fontSize: 14, lineHeight: 20, textAlignVertical: "top" }} />
220
+ style={{ minHeight: compact ? 66 : 58, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 8, borderWidth: 1, borderColor: c.border, color: c.foreground, backgroundColor: c.surface0, fontSize: 14, lineHeight: 20, textAlignVertical: "top" }} /></WithImages>
210
221
  <NoteLink icon="X" label="Remove note" a11y={`Remove the note${numbered ? ` on decision ${i + 1}` : ""}`} disabled={!!busy} onPress={() => { onNote?.(d.id, ""); onNoteOpen?.(d.id, false); setFocusNote(null); }} c={c} compact={compact} />
211
222
  </View> : done ? null : <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", columnGap: 14 }}>
212
223
  <NoteLink icon="MessageSquarePlus" label="Add note" a11y={numbered ? `Add note to decision ${i + 1}` : "Add note"} disabled={!!busy} onPress={() => { setFocusNote(d.id); onNoteOpen?.(d.id, true); }} c={c} compact={compact} />
@@ -386,6 +397,9 @@ function BriefCardBody({ item, theme, layout, agentId, deps, embedded = false, s
386
397
  const { height } = useWindowDimensions();
387
398
  const act = useRpc(briefActionRpc);
388
399
  const answerQuestion = useRpc(answerQuestionRpc);
400
+ // Pasted images on the answer or the note (every-agent-field-takes-images): they ride the answer to the brief's agent.
401
+ const img = useImageAttachments({ target: { kind: "agent", agentId } });
402
+ const withImages = () => { const images = img.uploads(); return images ? { images } : {}; };
389
403
  const browserRead = useRpc(browserStatusRpc);
390
404
  const [sending, setBusy] = useState<string | null>(null);
391
405
  // Until the server confirms this brief is the open one, every control waits ("checking" matches no button's key).
@@ -450,7 +464,7 @@ function BriefCardBody({ item, theme, layout, agentId, deps, embedded = false, s
450
464
  if (busy || marked) return;
451
465
  setError(null); setSent(false); setMarked(new Date().toISOString());
452
466
  const doneId = newAnswerId();
453
- const id = runUndoable("Telling the agent it's done", { label: "Done", toast, run: async (): Promise<unknown> => doneQ && workspace ? answerQuestion({ workspaceId: workspace.id, questionId: doneQ.id, choice: TASK_DONE.letter, ...(notesOpen[doneQ.id] && notes[doneQ.id]?.trim() ? { words: notes[doneQ.id].trim() } : {}), action: "send" })
467
+ const id = runUndoable("Telling the agent it's done", { label: "Done", toast, run: async (): Promise<unknown> => doneQ && workspace ? answerQuestion({ workspaceId: workspace.id, questionId: doneQ.id, choice: TASK_DONE.letter, ...(notesOpen[doneQ.id] && notes[doneQ.id]?.trim() ? { words: notes[doneQ.id].trim() } : {}), ...withImages(), action: "send" })
454
468
  : act({ agentId, briefId: b.id, move: "done", answerId: doneId }), success: "Marked done. The agent has it.",
455
469
  failure: "Done not sent", open: () => deps.openAgent(agentId), onSuccess: () => setSent(true), onError: e => { setMarked(null); setError(errorText(e)); }, reconcile: e => { setMarked(null); reconcile(e); } }, () => setMarked(null), `done:${b.id}`, () => deps.endDone?.(agentId));
456
470
  // The pill's Undo is this toast's Undo: it closes the toast (so nothing is sent) and reopens the card.
@@ -516,8 +530,13 @@ function BriefCardBody({ item, theme, layout, agentId, deps, embedded = false, s
516
530
  type DecisionPick = { decisionId: string; choice: string; words?: string };
517
531
  const asQuestions = (list: DecisionPick[]) => !!workspace && list.length > 0 && list.every(x => b.questionIds.includes(x.decisionId) && workspace.questions.some(q => q.id === x.decisionId && !q.answer && !q.closed));
518
532
  const answer = async (list: DecisionPick[], answerId: string) => {
519
- if (!asQuestions(list)) return act({ agentId, briefId: b.id, answerId, ...(list.length === 1 ? list[0] : { choices: list }) });
520
- for (const x of list) await answerQuestion({ workspaceId: workspace!.id, questionId: x.decisionId, choice: x.choice, ...(x.words ? { words: x.words } : {}), action: "send" });
533
+ // The field already says why (before Send); a key or a bar's Send can't get past it either.
534
+ if (img.blocked) throw new Error(img.blocked);
535
+ const images = withImages();
536
+ if (!asQuestions(list)) { const out = await act({ agentId, briefId: b.id, answerId, ...(list.length === 1 ? list[0] : { choices: list }), ...images }); img.clear(); return out; }
537
+ // The images ride the first answer's message: one message to the agent carries them once.
538
+ for (const [i, x] of list.entries()) await answerQuestion({ workspaceId: workspace!.id, questionId: x.decisionId, choice: x.choice, ...(x.words ? { words: x.words } : {}), ...(i === 0 ? images : {}), action: "send" });
539
+ img.clear();
521
540
  void cache.invalidateQueries({ queryKey: liveBriefKey(agentId) }); void cache.invalidateQueries({ queryKey: workspaceKey(workspace!.id) });
522
541
  };
523
542
  // A tap sends the letter, with the note when one is typed; a sent answer clears the card (clearCard).
@@ -559,7 +578,7 @@ function BriefCardBody({ item, theme, layout, agentId, deps, embedded = false, s
559
578
  <BriefBody b={b} c={c} compact={compact} tight={tight} embedded={embedded} height={height} mode={multi ? "select" : "send"} picks={picks}
560
579
  onPick={(decisionId, letter) => { if (!busy) pickStore.set(b.id, decisionId, letter); }} busy={busy} onSend={sendOne}
561
580
  words={words} onWords={(decisionId, t) => wordStore.set(b.id, decisionId, t)} onSendOther={sendOther}
562
- notes={notes} notesOpen={notesOpen} onNote={(decisionId, t) => noteStore.set(b.id, decisionId, t)} onNoteOpen={(decisionId, open) => noteOpenStore.set(b.id, decisionId, open ? "1" : "")} doneIds={doneQ ? [doneQ.id] : []} />
581
+ notes={notes} notesOpen={notesOpen} onNote={(decisionId, t) => noteStore.set(b.id, decisionId, t)} onNoteOpen={(decisionId, open) => noteOpenStore.set(b.id, decisionId, open ? "1" : "")} doneIds={doneQ ? [doneQ.id] : []} img={img} />
563
582
 
564
583
  {multi && <SendBar b={b} picks={sendable} noted={notedCount(sendable, openNotes)} busy={busy} error={error} onSend={sendAll} c={c} compact={compact} />}
565
584
 
@@ -7,6 +7,8 @@ import { Animated, PanResponder, Platform, View } from "react-native";
7
7
  import { Pressable, Text } from "./text";
8
8
  import { useRpc } from "@getpaseo/plugin/client";
9
9
  import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/ui";
10
+ import { ImageField, useImageAttachments } from "./image-attach";
11
+ import type { ImageUpload } from "../shared/images";
10
12
  import { useQuery } from "@tanstack/react-query";
11
13
  import { inboxBriefRpc } from "../shared/contracts";
12
14
  import { needsYou } from "../shared/attention";
@@ -125,9 +127,9 @@ export function CatchUp({ theme, compact, deps, navigation, onExit }: { theme: T
125
127
  const nextCard = cardOf(session.order[session.pos + 1]);
126
128
  useWorkspace(live, nextCard?.s.workspaceId ?? "", { enabled: !!nextCard?.s.workspaceId });
127
129
 
128
- const ask = async (words: string) => {
130
+ const ask = async (words: string, images?: ImageUpload[]) => {
129
131
  if (!card) return;
130
- const out = await extras.askContext({ workspaceId: card.s.workspaceId, agentId: card.s.agentId, cardKey: card.key, card: cardLabel(card, w).slice(0, 300), ask: words });
132
+ const out = await extras.askContext({ workspaceId: card.s.workspaceId, agentId: card.s.agentId, cardKey: card.key, card: cardLabel(card, w).slice(0, 300), ask: words, ...(images?.length ? { images } : {}) });
131
133
  setMore(false);
132
134
  // context-never-blocks-the-deck: the workstream waits, the deck moves on.
133
135
  if (out.request.state === "asking") setSession(s => park(s, out.request.id, card.key));
@@ -351,7 +353,7 @@ export function CatchUp({ theme, compact, deps, navigation, onExit }: { theme: T
351
353
  /** One card: who and what, the ask through its own surface's component, then the deck's moves pinned to the bottom. */
352
354
  function CardView({ card, w, theme, compact, deps, navigation, gone, more, setMore, request, waiting, onAsk, sameWorkspace, onDone, onSkip, onSkipWorkspace, wsLeft, onBack, onLater }: {
353
355
  card: DeckCard; w: ListWorkspace | undefined; theme: Theme; compact: boolean; deps: CatchUpDeps; navigation: Nav; gone: boolean; more: boolean; setMore: (v: boolean | ((v: boolean) => boolean)) => void;
354
- request: ContextRequest | null; waiting: boolean; onAsk: (words: string) => Promise<void>;
356
+ request: ContextRequest | null; waiting: boolean; onAsk: (words: string, images?: ImageUpload[]) => Promise<void>;
355
357
  sameWorkspace: string[]; onDone: () => void; onSkip: () => void; onSkipWorkspace?: () => void; wsLeft: number; onBack?: () => void; onLater: () => void;
356
358
  }) {
357
359
  const c = theme.colors; const t = text(c, compact);
@@ -425,7 +427,7 @@ function CardView({ card, w, theme, compact, deps, navigation, gone, more, setMo
425
427
  // a-move-bar-action-opens-in-view (MOVE_OPENS): More context and Later open where the eye is, a sheet above the
426
428
  // phone's bar or a popover on their button on desktop, never appended below the card.
427
429
  const closeMore = () => { setMore(false); if (!compact) focusSoon("catch-up-more"); };
428
- const moreBlock = more && <MorePanel theme={theme} compact={compact} onClose={closeMore} onAsk={onAsk} />;
430
+ const moreBlock = more && <MorePanel theme={theme} compact={compact} onClose={closeMore} onAsk={onAsk} target={s.workspaceId ? { kind: "workspace", workspaceId: s.workspaceId } : s.agentId ? { kind: "agent", agentId: s.agentId } : null} />;
429
431
  const later = (until: string) => { setLaterOpen(false); if (s.agentId) void deps.sources.inbox.snooze([s.agentId], until); onLater(); };
430
432
  const laterBlock = laterOpen && <View {...({ dataSet: { catchUpLater: "1" } } as object)} accessibilityRole="menu" accessibilityLabel="Later" style={{ gap: 8 }}>
431
433
  <Text style={[t.small, { fontWeight: "600" }]}>Back in your Needs you</Text>
@@ -572,9 +574,15 @@ function NoteRow({ theme, compact, agentId }: { theme: Theme; compact: boolean;
572
574
  const c = theme.colors;
573
575
  const agent = useAgentLive(agentId);
574
576
  const [words, setWords] = useState("");
575
- return <View {...PRIMARY_FORM} style={{ flexDirection: "row", alignItems: "flex-end", gap: 8 }}>
577
+ // Pasted images go with the words through Paseo's own send (every-agent-field-takes-images).
578
+ const img = useImageAttachments({ target: { kind: "agent", agentId } });
579
+ const send = () => {
580
+ const images = img.uploads()?.map(i => ({ data: i.data, mimeType: i.mimeType }));
581
+ void agent.handle?.send(words.trim(), images ? { images } : undefined); setWords(""); img.clear();
582
+ };
583
+ return <ImageField model={img} theme={theme} compact={compact}><View {...PRIMARY_FORM} style={{ flexDirection: "row", alignItems: "flex-end", gap: 8 }}>
576
584
  <TextInput accessibilityLabel="Tell the agent something" placeholder="Tell the agent something" placeholderTextColor={c.foregroundMuted} value={words} onChangeText={setWords} multiline
577
585
  style={{ flex: 1, minHeight: compact ? 44 : 36, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, backgroundColor: c.surface0 }} />
578
- <IconButton theme={theme} compact={compact} icon="Send" label="Send to the agent" tooltip={!compact} disabled={!words.trim()} onPress={() => { void agent.handle?.send(words.trim()); setWords(""); }} />
579
- </View>;
586
+ <IconButton theme={theme} compact={compact} icon="Send" label="Send to the agent" tooltip={!compact} disabled={!words.trim() || !!img.blocked} onPress={send} />
587
+ </View></ImageField>;
580
588
  }
@@ -0,0 +1,323 @@
1
+ import { useEffect, useState } from "react";
2
+ import { ActivityIndicator, TextInput, View } from "react-native";
3
+ import { useRpc } from "@getpaseo/plugin/client";
4
+ import { Icon, SettingsSection, useToast } from "@getpaseo/plugin/client/ui";
5
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
6
+ import { Pressable, Text } from "./text";
7
+ import { Button, SubmitScope, Switch, errorText, text, type Theme } from "./kit";
8
+ import { RichText } from "./rich-text";
9
+ import { raised, tint } from "./theme";
10
+ import { compassFindRpc, compassRpc, readCompassRpc, setCompassRpc } from "../shared/contracts";
11
+ import {
12
+ COMPASS, ROLES, ROLE_INFO, type CompassChange, type CompassNote, type CompassSource, type GlossaryEntry, type Place, type Preset, type PresetView, type Role, type Who,
13
+ } from "../shared/compass";
14
+
15
+ export const compassKey = ["follow-up", "compass"];
16
+
17
+ type View_ = {
18
+ settings: { sources: CompassSource[]; instructions: string; glossary: GlossaryEntry[] };
19
+ readers: { conversation: boolean; history: boolean };
20
+ presets: PresetView[];
21
+ blocked: string | null;
22
+ places: Record<string, { status: string; readAt: string | null; at: string | null; error: string | null }>;
23
+ notes: CompassNote[];
24
+ workspaces: Record<string, string>;
25
+ unplaced: number;
26
+ lastRead: { at: string; trigger: string; ok: boolean; notes: number; error: string | null } | null;
27
+ today: { extractions: number; cap: number };
28
+ running: boolean;
29
+ };
30
+ type Found = { id: string; name: string; place: Place };
31
+
32
+ const clock = (iso: string) => new Date(iso).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
33
+ const placeName = (p: Place) => p.kind === "conversation" ? (p.sub === "dm" ? `DM with ${p.name}` : `#${p.name}`) : p.name;
34
+ /** "DM with Dana" when the source is one person read in their DM; else "Dana in #planning, DM with Avi". */
35
+ const whoWhere = (s: CompassSource) => s.who.kind === "person" && s.places.length === 1 && s.places[0].kind === "conversation" && s.places[0].sub === "dm" && s.places[0].id === s.who.person.id
36
+ ? placeName(s.places[0]) : `${whoName(s.who)} in ${s.places.map(placeName).join(", ")}`;
37
+ const day = (d: string) => new Date(`${d}T12:00:00`).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric" });
38
+ const whoName = (w: Who) => w.kind === "person" ? w.person.name : w.kind === "people" ? w.people.map(p => p.name).join(", ") : w.kind === "me" ? "You" : "Everyone";
39
+
40
+ /**
41
+ * Settings → Morning brief → Compass (docs/compass.md): the people and places that set the developer's priorities, how
42
+ * to read them, and the glossary. One editor for every source; presets only fill its fields. Every change goes through
43
+ * the RPC `set_compass` runs, and Read now through `read_compass`.
44
+ */
45
+ export function CompassSection({ theme, compact }: { theme: Theme; compact: boolean }) {
46
+ const c = theme.colors; const t = text(c, compact);
47
+ const read = useRpc(compassRpc); const write = useRpc(setCompassRpc); const readNow = useRpc(readCompassRpc);
48
+ const cache = useQueryClient(); const toast = useToast();
49
+ const query = useQuery({ queryKey: compassKey, queryFn: async () => await read({}) as View_, refetchInterval: q => q.state.data?.running ? 2_000 : 30_000 });
50
+ const change = useMutation({
51
+ mutationFn: async (input: CompassChange) => await write(input) as View_,
52
+ onSuccess: value => cache.setQueryData(compassKey, value),
53
+ onError: error => toast.error(errorText(error)),
54
+ });
55
+ const reading = useMutation({
56
+ mutationFn: async () => await readNow({}) as { running: boolean; view: View_ },
57
+ onSuccess: r => cache.setQueryData(compassKey, r.view),
58
+ onError: error => toast.error(errorText(error)),
59
+ });
60
+ const [editing, setEditing] = useState<string | "new" | null>(null);
61
+ const data = query.data;
62
+ const full = !!data && data.settings.sources.length >= COMPASS.sources;
63
+ return <SettingsSection title="Compass" info="The people and places that set your priorities. Follow-up reads what they say each workday morning, keeps a note of each priority with their words, and AI priority ranks your work by it. Only the people you pick are read, only through read-only tools, and a fast model with no tools reads it. Agents can set it up too.">
64
+ {query.isPending && <ActivityIndicator accessibilityLabel="Loading Compass" color={c.foregroundMuted} style={{ alignSelf: "flex-start", marginVertical: 8 }} />}
65
+ {query.error && <Text style={[t.meta, { color: c.statusWarning }]}>{`Couldn't load Compass: ${errorText(query.error)}`}</Text>}
66
+ {data?.blocked && <Line icon="TriangleAlert" tone={c.statusWarning} text={data.blocked} theme={theme} compact={compact} />}
67
+ {data && <View style={{ ...raised(c), borderRadius: 10, backgroundColor: c.surface1, overflow: "hidden" }}>
68
+ {data.settings.sources.length === 0 && editing !== "new" && <View style={{ padding: compact ? 14 : 12, gap: 4 }}>
69
+ <Text style={[t.label, { color: c.foreground }]}>Nobody sets your priorities here yet</Text>
70
+ <Text style={t.meta}>Add the person whose words decide what you work on first, like your product lead's DM. Or ask the Overseer to set it up for you.</Text>
71
+ </View>}
72
+ {data.settings.sources.map((s, i) => editing === s.id
73
+ ? <SourceEditor key={s.id} view={data} source={s} first={i === 0} busy={change.isPending} theme={theme} compact={compact} onCancel={() => setEditing(null)}
74
+ onSave={input => change.mutate(input, { onSuccess: () => setEditing(null) })} onRemove={() => change.mutate({ remove: s.id }, { onSuccess: () => setEditing(null) })} />
75
+ : <SourceRow key={s.id} view={data} source={s} first={i === 0} busy={change.isPending} theme={theme} compact={compact} onEdit={() => setEditing(s.id)}
76
+ onToggle={on => change.mutate({ source: { id: s.id, enabled: on } })} />)}
77
+ {editing === "new" && <SourceEditor view={data} first={data.settings.sources.length === 0} busy={change.isPending} theme={theme} compact={compact} onCancel={() => setEditing(null)}
78
+ onSave={input => change.mutate(input, { onSuccess: () => setEditing(null) })} />}
79
+ </View>}
80
+ {data && editing !== "new" && <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
81
+ {full
82
+ ? <Text style={t.meta}>{`Compass holds ${COMPASS.sources} sources. Remove one to add another.`}</Text>
83
+ : <Button title="Add a source" icon="Plus" theme={theme} compact={compact} disabled={!!editing} onPress={() => setEditing("new")} />}
84
+ {data.settings.sources.length > 0 && <Button title="Read now" icon="RotateCcw" kind="ghost" theme={theme} compact={compact} loading={reading.isPending || data.running} disabled={!!data.blocked} onPress={() => reading.mutate()} />}
85
+ {data.settings.sources.length > 0 && <Text style={t.meta}>{statusLine(data)}</Text>}
86
+ </View>}
87
+ {data && <ReadingNotes value={data.settings.instructions} busy={change.isPending} theme={theme} compact={compact} onSave={v => change.mutate({ instructions: v })} />}
88
+ {data && <Glossary entries={data.settings.glossary} busy={change.isPending} theme={theme} compact={compact} onSave={g => change.mutate({ glossary: g })} />}
89
+ </SettingsSection>;
90
+ }
91
+
92
+ /** "Read 09:02 · 3 notes live · 1 not matched to a workspace", or why the last read failed. */
93
+ function statusLine(v: View_): string {
94
+ if (v.running) return "Reading…";
95
+ // One source already shows its count on its row; the total is news only with several.
96
+ const parts = [v.lastRead ? `Read ${clock(v.lastRead.at)}` : "Not read yet", ...(v.settings.sources.length > 1 ? [`${v.notes.length} note${v.notes.length === 1 ? "" : "s"} live`] : [])];
97
+ if (v.unplaced) parts.push(`${v.unplaced} not matched to a workspace`);
98
+ if (v.today.extractions >= v.today.cap) parts.push(`paused until tomorrow: ${v.today.cap} reads today`);
99
+ return parts.join(" · ");
100
+ }
101
+
102
+ function Line({ icon, tone, text: line, theme, compact }: { icon: string; tone: string; text: string; theme: Theme; compact: boolean }) {
103
+ const t = text(theme.colors, compact);
104
+ return <View style={{ flexDirection: "row", alignItems: "flex-start", gap: 6 }}>
105
+ <View style={{ paddingTop: compact ? 4 : 3 }}><Icon name={icon} size={12} color={tone} /></View>
106
+ <Text style={[t.meta, { color: tone, flex: 1 }]}>{line}</Text>
107
+ </View>;
108
+ }
109
+
110
+ /** One source, read-only: who, where, its roles, its reading notes' first line, how its places read. Edit opens the editor in place. */
111
+ function SourceRow({ view, source, first, busy, onEdit, onToggle, theme, compact }: { view: View_; source: CompassSource; first: boolean; busy: boolean; onEdit: () => void; onToggle: (on: boolean) => void; theme: Theme; compact: boolean }) {
112
+ const c = theme.colors; const t = text(c, compact);
113
+ const notes = view.notes.filter(n => n.source === source.id); const live = notes.length;
114
+ const [open, setOpen] = useState(false);
115
+ const bad = source.places.map(p => view.places[`${p.kind}:${p.id}`]).find(p => p && (p.status === "failed" || p.status === "paused"));
116
+ const slow = source.places.some(p => view.places[`${p.kind}:${p.id}`]?.status === "slow-path");
117
+ return <View style={{ flexDirection: "row", gap: 10, alignItems: "flex-start", padding: compact ? 14 : 12, borderTopWidth: first ? 0 : 1, borderTopColor: c.border }}>
118
+ <View style={{ flex: 1, minWidth: 0, gap: 4 }}>
119
+ <RichText plain style={[t.label, { color: source.enabled ? c.foreground : c.foregroundMuted }]}>{source.label}</RichText>
120
+ <Text style={t.meta}>{whoWhere(source)}</Text>
121
+ <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 6 }}>
122
+ {source.roles.map(r => <View key={r} style={{ paddingHorizontal: 8, minHeight: 20, justifyContent: "center", borderRadius: 999, backgroundColor: c.surface2 }}>
123
+ <Text style={[t.meta, { color: c.foreground }]}>{ROLE_INFO[r].label}</Text>
124
+ </View>)}
125
+ </View>
126
+ {source.instructions ? <RichText plain numberOfLines={2} style={[t.meta, { fontStyle: "italic" }]}>{`“${source.instructions}”`}</RichText> : null}
127
+ {source.enabled && (live
128
+ ? <Pressable accessibilityRole="button" accessibilityState={{ expanded: open }} accessibilityLabel={`${open ? "Hide" : "Show"} ${live} note${live === 1 ? "" : "s"} from ${source.label}`} onPress={() => setOpen(o => !o)} hitSlop={compact ? 0 : 6}
129
+ style={{ flexDirection: "row", alignItems: "center", gap: 4, alignSelf: "flex-start", minHeight: compact ? 44 : 20 }}>
130
+ <Text style={[t.meta, { color: c.foreground }]}>{`${live} note${live === 1 ? "" : "s"} live`}</Text>
131
+ <Icon name={open ? "ChevronUp" : "ChevronDown"} size={12} color={c.foregroundMuted} />
132
+ {slow && <Text style={t.meta}>· read by search, the slower path</Text>}
133
+ </Pressable>
134
+ : <Text style={t.meta}>{["No notes live", slow ? "read by search, the slower path" : null].filter(Boolean).join(" · ")}</Text>)}
135
+ {source.enabled && open && <NoteList notes={notes} view={view} theme={theme} compact={compact} />}
136
+ {source.enabled && bad?.error && <Line icon="TriangleAlert" tone={c.statusWarning} text={bad.error} theme={theme} compact={compact} />}
137
+ <Pressable accessibilityRole="button" accessibilityLabel={`Edit ${source.label}`} onPress={onEdit} disabled={busy} hitSlop={compact ? 0 : 6}
138
+ style={{ flexDirection: "row", alignItems: "center", gap: 4, alignSelf: "flex-start", minHeight: compact ? 44 : 20 }}>
139
+ <Icon name="Pencil" size={12} color={c.accent} />
140
+ <Text style={[t.meta, { color: c.accent, fontWeight: "600" }]}>Edit</Text>
141
+ </Pressable>
142
+ </View>
143
+ <Switch theme={theme} compact={compact} label={compact ? "" : source.enabled ? "On" : "Off"} accessibilityLabel={`Read ${source.label}`} value={source.enabled} disabled={busy} onChange={onToggle} />
144
+ </View>;
145
+ }
146
+
147
+ /**
148
+ * What Compass understood from a source: each live note, the words it quotes, its date and where it went. The quote is
149
+ * the proof (a-compass-note-quotes-its-source), so it is always shown.
150
+ */
151
+ function NoteList({ notes, view, theme, compact }: { notes: CompassNote[]; view: View_; theme: Theme; compact: boolean }) {
152
+ const c = theme.colors; const t = text(c, compact);
153
+ const where = (n: CompassNote) => n.match.workspace ? view.workspaces[n.match.workspace] ?? "its workspace" : n.match.issue ? n.match.issue : "not matched to a workspace";
154
+ return <View style={{ gap: 10, paddingTop: 2 }}>
155
+ {notes.map(n => <View key={n.id} style={{ gap: 2, paddingLeft: 10, borderLeftWidth: 2, borderLeftColor: c.border }}>
156
+ <RichText plain style={[t.body, { color: c.foreground }]}>{n.what}</RichText>
157
+ {n.quote && <RichText plain numberOfLines={3} style={[t.meta, { fontStyle: "italic" }]}>{`“${n.quote}”`}</RichText>}
158
+ <Text style={[t.meta, { fontVariant: ["tabular-nums"] }]}>{[n.until ? `Until ${day(n.until)}` : null, ROLE_INFO[n.role].label, where(n)].filter(Boolean).join(" · ")}</Text>
159
+ </View>)}
160
+ </View>;
161
+ }
162
+
163
+ /**
164
+ * The one editor for adding and changing a source. A preset only fills the fields. Who and where are picked from the chat
165
+ * tool's own search (compass_find), so every place has the tool's own id; a person's DM comes with the person.
166
+ */
167
+ function SourceEditor({ view, source, first, busy, onSave, onCancel, onRemove, theme, compact }: { view: View_; source?: CompassSource; first: boolean; busy: boolean; onSave: (c: CompassChange) => void; onCancel: () => void; onRemove?: () => void; theme: Theme; compact: boolean }) {
168
+ const c = theme.colors; const t = text(c, compact);
169
+ const [preset, setPreset] = useState<Preset | null>(source ? null : view.presets.find(p => p.offered) ?? null);
170
+ const [people, setPeople] = useState<Found[]>(source ? source.who.kind === "person" ? [{ id: source.who.person.id, name: source.who.person.name, place: null! }] : source.who.kind === "people" ? source.who.people.map(p => ({ id: p.id, name: p.name, place: null! })) : [] : []);
171
+ const [me, setMe] = useState(source?.who.kind === "me" || preset?.who === "me");
172
+ const [places, setPlaces] = useState<Place[]>(source?.places ?? []);
173
+ const [roles, setRoles] = useState<Role[]>(source?.roles ?? preset?.roles ?? ["priorities"]);
174
+ const [label, setLabel] = useState(source?.label ?? "");
175
+ const [notes, setNotes] = useState(source?.instructions ?? "");
176
+ const [picking, setPicking] = useState<"people" | "channels" | null>(null);
177
+ const usePreset = (p: Preset) => { setPreset(p); setRoles(p.roles); setMe(p.who === "me"); if (p.who === "me") setPeople([]); };
178
+ const dmOnly = preset?.sub === "dm";
179
+ const addPerson = (f: Found) => {
180
+ setPicking(null);
181
+ setPeople(ps => ps.some(p => p.id === f.id) || ps.length >= COMPASS.people ? ps : [...ps, f]);
182
+ // A person's DM preset: their DM is the place.
183
+ if (dmOnly) setPlaces(ps => ps.some(p => p.id === f.id) ? ps : [...ps, f.place].slice(0, COMPASS.places));
184
+ if (!label && !source) setLabel(f.name);
185
+ };
186
+ const who: Who | null = me ? { kind: "me" } : people.length === 1 ? { kind: "person", person: { id: people[0].id, name: people[0].name } } : people.length > 1 ? { kind: "people", people: people.map(p => ({ id: p.id, name: p.name })) } : null;
187
+ const ready = !!who && places.length > 0 && roles.length > 0;
188
+ const save = () => who && onSave({ source: { ...(source ? { id: source.id } : {}), ...(label.trim() ? { label: label.trim() } : {}), who, places, roles, instructions: notes } });
189
+ const chip = (title: string, onRemoveChip: () => void, key: string) => <View key={key} style={{ flexDirection: "row", alignItems: "center", gap: 4, minHeight: compact ? 44 : 28, paddingLeft: 10, paddingRight: 4, borderRadius: 6, borderWidth: 1, borderColor: c.border, backgroundColor: c.surface0 }}>
190
+ <Text style={t.body}>{title}</Text>
191
+ <Pressable accessibilityRole="button" accessibilityLabel={`Remove ${title}`} onPress={onRemoveChip} hitSlop={6} style={{ minWidth: compact ? 36 : 22, minHeight: compact ? 36 : 22, alignItems: "center", justifyContent: "center" }}>
192
+ <Icon name="X" size={12} color={c.foregroundMuted} />
193
+ </Pressable>
194
+ </View>;
195
+ const labelCol = (s: string) => <Text style={[t.meta, { width: compact ? undefined : 96, minWidth: compact ? 64 : undefined }]}>{s}</Text>;
196
+ const row = { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 } as const;
197
+ return <SubmitScope enabled={ready && !busy} onSubmit={save} style={{ padding: compact ? 14 : 12, gap: 12, borderTopWidth: first ? 0 : 1, borderTopColor: c.border, backgroundColor: c.surface1 }}>
198
+ {!source && <View style={{ gap: 6 }}>
199
+ <Text style={[t.meta, { color: c.foreground, fontWeight: "600" }]}>Start from</Text>
200
+ <View style={row}>
201
+ {view.presets.filter(p => p.offered).map(p => <Pressable key={p.id} accessibilityRole="radio" accessibilityState={{ checked: preset?.id === p.id }} onPress={() => usePreset(p)}
202
+ style={state => ({ minHeight: compact ? 44 : 30, paddingHorizontal: 12, borderRadius: 6, justifyContent: "center", borderWidth: 1, borderColor: preset?.id === p.id ? c.accent : c.border,
203
+ backgroundColor: preset?.id === p.id ? tint(c.accent, c) : (state as { hovered?: boolean }).hovered ? c.surface2 : c.surface0 })}>
204
+ <Text style={{ color: c.foreground, fontSize: 13, fontWeight: "500" }}>{p.label}</Text>
205
+ </Pressable>)}
206
+ </View>
207
+ {preset && <Text style={t.meta}>{preset.hint}</Text>}
208
+ {view.presets.some(p => !p.offered) && <Text style={t.meta}>{`Not yet: ${view.presets.filter(p => !p.offered).map(p => p.label.toLowerCase()).join(", ")}. Compass reads conversations in this release.`}</Text>}
209
+ </View>}
210
+ <View style={row}>
211
+ {labelCol("Whose words")}
212
+ {me ? <Text style={t.body}>Yours</Text> : people.map(p => chip(p.name, () => { setPeople(ps => ps.filter(x => x.id !== p.id)); if (dmOnly) setPlaces(ps => ps.filter(x => x.id !== p.id)); }, p.id))}
213
+ {!me && people.length < COMPASS.people && <Button title={people.length ? "Add a person" : "Pick a person"} icon="Plus" kind={people.length ? "ghost" : "secondary"} theme={theme} compact={compact} onPress={() => setPicking(picking === "people" ? null : "people")} />}
214
+ </View>
215
+ {picking === "people" && <FindPicker kind="people" theme={theme} compact={compact} onCancel={() => setPicking(null)} onPick={addPerson} />}
216
+ <View style={row}>
217
+ {labelCol("Where")}
218
+ {places.map(p => chip(placeName(p), () => setPlaces(ps => ps.filter(x => x !== p)), `${p.kind}:${p.id}`))}
219
+ {places.length < COMPASS.places && !dmOnly && <Button title={places.length ? "Add" : "Pick a channel"} icon="Plus" kind={places.length ? "ghost" : "secondary"} theme={theme} compact={compact} onPress={() => setPicking(picking === "channels" ? null : "channels")} />}
220
+ {dmOnly && !places.length && <Text style={t.meta}>Their DM with you, once you pick them.</Text>}
221
+ </View>
222
+ {picking === "channels" && <FindPicker kind="channels" theme={theme} compact={compact} onCancel={() => setPicking(null)} onPick={f => { setPicking(null); setPlaces(ps => ps.some(p => p.id === f.id) ? ps : [...ps, f.place]); }} />}
223
+ <View style={{ gap: 6 }}>
224
+ <Text style={[t.meta, { color: c.foreground, fontWeight: "600" }]}>What they tell you</Text>
225
+ <View style={row}>
226
+ {ROLES.map(r => { const on = roles.includes(r); return <Pressable key={r} accessibilityRole="checkbox" accessibilityState={{ checked: on }} onPress={() => setRoles(rs => on ? rs.filter(x => x !== r) : [...rs, r])}
227
+ style={state => ({ minHeight: compact ? 44 : 28, paddingHorizontal: 10, borderRadius: 999, justifyContent: "center", borderWidth: 1, borderColor: on ? c.accent : c.border,
228
+ backgroundColor: on ? tint(c.accent, c) : (state as { hovered?: boolean }).hovered ? c.surface2 : "transparent" })}>
229
+ <Text style={{ color: on ? c.foreground : c.foregroundMuted, fontSize: 12, fontWeight: "500" }}>{ROLE_INFO[r].label}</Text>
230
+ </Pressable>; })}
231
+ </View>
232
+ </View>
233
+ <View style={{ gap: 6 }}>
234
+ <Text style={[t.meta, { color: c.foreground, fontWeight: "600" }]}>How to read this</Text>
235
+ <TextInput accessibilityLabel="How to read this source" multiline value={notes} onChangeText={v => setNotes(v.slice(0, COMPASS.sourceInstructions))} placeholder="P0 means today, P1 this week. Ignore hiring talk."
236
+ placeholderTextColor={c.foregroundMuted} style={{ minHeight: 64, padding: 10, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, fontSize: 13, backgroundColor: c.surface0, textAlignVertical: "top" }} />
237
+ <Text style={t.meta}>{`Your words for the model that reads it. They change how messages are read, never what is read. ${notes.length}/${COMPASS.sourceInstructions}`}</Text>
238
+ </View>
239
+ <View style={row}>
240
+ {labelCol("Name")}
241
+ <TextInput accessibilityLabel="Source name" value={label} onChangeText={setLabel} placeholder="Dana · product" placeholderTextColor={c.foregroundMuted}
242
+ style={{ flex: 1, minWidth: 160, minHeight: compact ? 44 : 32, paddingHorizontal: 10, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, fontSize: 13, backgroundColor: c.surface0 }} />
243
+ </View>
244
+ <View style={[row, { justifyContent: "space-between" }]}>
245
+ <View style={row}>
246
+ <Button title={source ? "Save" : "Add source"} kind="primary" shortcut theme={theme} compact={compact} loading={busy} disabled={!ready} onPress={save} />
247
+ <Button title="Cancel" kind="ghost" theme={theme} compact={compact} onPress={onCancel} />
248
+ </View>
249
+ {onRemove && <Button title="Remove source" kind="ghost" icon="Trash2" theme={theme} compact={compact} disabled={busy} onPress={onRemove} />}
250
+ </View>
251
+ {!ready && <Text style={t.meta}>{!who ? "Pick whose words count." : !places.length ? "Pick where to read them." : "Give it at least one role."}</Text>}
252
+ </SubmitScope>;
253
+ }
254
+
255
+ /** People or channels from the chat tool's own search (compass_find): only results with the tool's own id can be picked. */
256
+ function FindPicker({ kind, onPick, onCancel, theme, compact }: { kind: "people" | "channels"; onPick: (f: Found) => void; onCancel: () => void; theme: Theme; compact: boolean }) {
257
+ const c = theme.colors; const t = text(c, compact);
258
+ const find = useRpc(compassFindRpc);
259
+ const [q, setQ] = useState(""); const [debounced, setDebounced] = useState("");
260
+ useEffect(() => { const id = setTimeout(() => setDebounced(q.trim()), 350); return () => clearTimeout(id); }, [q]);
261
+ const results = useQuery({ queryKey: ["follow-up", "compass-find", kind, debounced], enabled: debounced.length >= 2, staleTime: 60_000,
262
+ queryFn: async () => await find({ kind, query: debounced }) as { results: Found[]; error: string | null } });
263
+ return <View style={{ borderWidth: 1, borderColor: c.border, borderRadius: 8, backgroundColor: c.surface0, overflow: "hidden" }}>
264
+ <View style={{ flexDirection: "row", gap: 8, padding: 8, alignItems: "center" }}>
265
+ <TextInput autoFocus accessibilityLabel={kind === "people" ? "Search people" : "Search channels"} value={q} onChangeText={setQ} placeholder={kind === "people" ? "Search people by name" : "Search channels by name"}
266
+ placeholderTextColor={c.foregroundMuted} autoCapitalize="none" autoCorrect={false}
267
+ style={{ flex: 1, minWidth: 0, minHeight: compact ? 44 : 32, paddingHorizontal: 10, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, fontSize: 13, backgroundColor: c.surface1 }} />
268
+ <Button title="Cancel" kind="ghost" theme={theme} compact={compact} onPress={onCancel} />
269
+ </View>
270
+ {results.isFetching && <Text style={[t.meta, { paddingHorizontal: 12, paddingBottom: 8 }]}>Searching…</Text>}
271
+ {results.data?.error && <Text style={[t.meta, { paddingHorizontal: 12, paddingBottom: 8, color: c.statusWarning }]}>{results.data.error}</Text>}
272
+ {(results.data?.results ?? []).map(r => <Pressable key={r.id} accessibilityRole="button" onPress={() => onPick(r)}
273
+ style={state => ({ minHeight: compact ? 44 : 34, paddingHorizontal: 12, justifyContent: "center", borderTopWidth: 1, borderTopColor: c.border, backgroundColor: state.pressed || (state as { hovered?: boolean }).hovered ? c.surface2 : "transparent" })}>
274
+ <Text style={t.body}>{kind === "people" ? r.name : `#${r.name}`}</Text>
275
+ </Pressable>)}
276
+ {debounced.length >= 2 && !results.isFetching && !results.data?.results.length && !results.data?.error && <Text style={[t.meta, { paddingHorizontal: 12, paddingBottom: 8 }]}>{`Nothing matches "${debounced}".`}</Text>}
277
+ </View>;
278
+ }
279
+
280
+ /** "How to read your Compass": the developer's words for every source, saved on Save. */
281
+ function ReadingNotes({ value, busy, onSave, theme, compact }: { value: string; busy: boolean; onSave: (v: string) => void; theme: Theme; compact: boolean }) {
282
+ const c = theme.colors; const t = text(c, compact);
283
+ const [draft, setDraft] = useState(value);
284
+ useEffect(() => setDraft(value), [value]);
285
+ const dirty = draft.trim() !== value.trim();
286
+ return <SubmitScope enabled={dirty && !busy} onSubmit={() => onSave(draft)} style={{ gap: 6 }}>
287
+ <Text style={[t.label, { color: c.foreground }]}>How to read your Compass</Text>
288
+ <TextInput accessibilityLabel="How to read your Compass" multiline value={draft} onChangeText={v => setDraft(v.slice(0, COMPASS.instructions))} placeholder="P0 means today. 'The renewal' is the acme renewal. Customer asks wait for the plan unless they name a date."
289
+ placeholderTextColor={c.foregroundMuted} style={{ minHeight: 72, padding: 10, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, fontSize: 13, backgroundColor: c.surface0, textAlignVertical: "top" }} />
290
+ <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
291
+ <Text style={[t.meta, { flex: 1, minWidth: 180 }]}>{`For every source. ${draft.length}/${COMPASS.instructions}`}</Text>
292
+ {dirty && <Button title="Save" kind="primary" shortcut theme={theme} compact={compact} loading={busy} onPress={() => onSave(draft)} />}
293
+ </View>
294
+ </SubmitScope>;
295
+ }
296
+
297
+ /** The glossary: your words → an issue key. Matching reads it before anything else, word for word. */
298
+ function Glossary({ entries, busy, onSave, theme, compact }: { entries: GlossaryEntry[]; busy: boolean; onSave: (g: GlossaryEntry[]) => void; theme: Theme; compact: boolean }) {
299
+ const c = theme.colors; const t = text(c, compact);
300
+ const [words, setWords] = useState(""); const [key, setKey] = useState("");
301
+ const means = (g: GlossaryEntry) => "issue" in g.means ? g.means.issue : "workspace" in g.means ? `workspace ${g.means.workspace}` : g.means.account;
302
+ const field = { minHeight: compact ? 44 : 32, paddingHorizontal: 10, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, fontSize: 13, backgroundColor: c.surface0 } as const;
303
+ const add = () => { onSave([...entries, { words: words.trim(), means: { issue: key.trim().toUpperCase() } }]); setWords(""); setKey(""); };
304
+ return <View style={{ gap: 6 }}>
305
+ <Text style={[t.label, { color: c.foreground }]}>Glossary</Text>
306
+ <Text style={t.meta}>Your own words for your work. When a note says one, it goes to that issue's workspace.</Text>
307
+ {entries.map(g => <View key={g.words} style={{ flexDirection: "row", alignItems: "center", gap: 8, minHeight: compact ? 44 : 28 }}>
308
+ <RichText plain style={[t.body, { color: c.foreground }]}>{`“${g.words}”`}</RichText>
309
+ <Icon name="ArrowRight" size={12} color={c.foregroundMuted} />
310
+ <Text style={[t.body, { fontFamily: "ui-monospace, Menlo, monospace", fontSize: 12 }]}>{means(g)}</Text>
311
+ <Pressable accessibilityRole="button" accessibilityLabel={`Remove ${g.words}`} disabled={busy} onPress={() => onSave(entries.filter(x => x !== g))} hitSlop={6}
312
+ style={{ minWidth: compact ? 44 : 22, minHeight: compact ? 44 : 22, alignItems: "center", justifyContent: "center" }}>
313
+ <Icon name="X" size={12} color={c.foregroundMuted} />
314
+ </Pressable>
315
+ </View>)}
316
+ {entries.length < COMPASS.glossary && <View style={{ flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 }}>
317
+ <TextInput accessibilityLabel="Word" value={words} onChangeText={setWords} placeholder="Phoenix" placeholderTextColor={c.foregroundMuted} style={[field, { flexGrow: 1, flexBasis: 120, minWidth: 0 }]} />
318
+ <Icon name="ArrowRight" size={12} color={c.foregroundMuted} />
319
+ <TextInput accessibilityLabel="Issue key" value={key} onChangeText={setKey} placeholder="ACME-40" autoCapitalize="characters" placeholderTextColor={c.foregroundMuted} style={[field, { flexGrow: 1, flexBasis: 100, minWidth: 0, fontFamily: "ui-monospace, Menlo, monospace" }]} />
320
+ <Button title="Add" icon="Plus" theme={theme} compact={compact} loading={busy} disabled={words.trim().length < 2 || key.trim().length < 3} onPress={add} />
321
+ </View>}
322
+ </View>;
323
+ }
@@ -1,5 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
2
2
  import { Platform, TextInput, View } from "react-native";
3
+ import { AttachImageButton, ImageField, useImageAttachments, type ImageAttachments } from "./image-attach";
4
+ import { OVERSEER_ASK_KEY } from "./unsent-images";
3
5
  import { Pressable, Text } from "./text";
4
6
  import { Icon, ScrollView, useToast } from "@getpaseo/plugin/client/ui";
5
7
  import { homeCounts, type HomeGroupId, type HomeModel } from "../shared/home";
@@ -37,6 +39,8 @@ export type Omnibox = {
37
39
  inputRef: React.RefObject<TextInput | null>;
38
40
  /** The Overseer is on, so a query can also be an ask. */
39
41
  askOn: boolean;
42
+ /** Images pasted or dropped on the search while the Overseer is on: they go with the ask (every-agent-field-takes-images). */
43
+ images: ImageAttachments;
40
44
  };
41
45
 
42
46
  /**
@@ -55,6 +59,8 @@ export function useOmnibox(model: HomeModel, sources: HomeSources, extraProvider
55
59
  const searching = query.trim().length > 0;
56
60
  const overseer = useSyncExternalStore(sources.extras.subscribe, sources.extras.overseer, sources.extras.overseer);
57
61
  const askOn = !!overseer?.enabled;
62
+ // An ask Paseo hasn't taken yet keeps its images under OVERSEER_ASK_KEY (client/unsent-images.ts).
63
+ const images = useImageAttachments({ target: askOn ? { kind: "overseer" } : null, keep: OVERSEER_ASK_KEY });
58
64
  // Linked keys and titles: fetched only while there's a query (client/linked.tsx explains why).
59
65
  const linked = useLinkedIndex(searching);
60
66
  // Built lazily: nothing is indexed until the developer types.
@@ -72,7 +78,7 @@ export function useOmnibox(model: HomeModel, sources: HomeSources, extraProvider
72
78
  const token = useSyncExternalStore(sources.extras.subscribe, sources.extras.focusToken, sources.extras.focusToken);
73
79
  useEffect(() => { if (sources.extras.takeFocus()) inputRef.current?.focus(); }, [token, sources.extras]);
74
80
  const hint = layoutHint((results ?? []).flatMap(r => r.hit ? [r.hit] : []));
75
- return { query, setQuery, setPhysical, layoutHint: hint, results, active: Math.min(current, Math.max(0, (results?.length ?? 1) - 1)), move, inputRef, askOn };
81
+ return { query, setQuery, setPhysical, layoutHint: hint, results, active: Math.min(current, Math.max(0, (results?.length ?? 1) - 1)), move, inputRef, askOn, images };
76
82
  }
77
83
 
78
84
  type DomKey = { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; target: unknown; preventDefault(): void };
@@ -97,7 +103,9 @@ export function useSlashToFocus(omnibox: Omnibox, enabled = true) {
97
103
  * The one query field: Home's omnibox (SearchField) and the sidebar view's filter (FilterField) are this with
98
104
  * different words. `dense` is the phone layout: a 44px field with a rounder shape and body-size text.
99
105
  */
100
- export function QueryField({ theme, value, onChange, placeholder, icon, dense, inputRef, slashHint, slashTitle, onSubmit, onArrow, listKeys = false, count, autoFocus = false, onEscape, onLayoutQuery }: {
106
+ export function QueryField({ theme, value, onChange, placeholder, icon, dense, inputRef, slashHint, slashTitle, onSubmit, onArrow, listKeys = false, count, autoFocus = false, onEscape, onLayoutQuery, trailing }: {
107
+ /** A control at the field's end, before its ✕ (Home's search asking the Overseer: Add image). */
108
+ trailing?: ReactNode;
101
109
  /** Its arrows step into the list below (client/list-keys.ts): the sidebar filter, and Home's search while empty. */
102
110
  listKeys?: boolean;
103
111
  onLayoutQuery?: (q: string | null) => void;
@@ -153,6 +161,7 @@ export function QueryField({ theme, value, onChange, placeholder, icon, dense, i
153
161
  else if (key === "Escape") { if (onEscape) onEscape(); else if (value) onChange(""); else inputRef.current?.blur(); }
154
162
  }}
155
163
  style={{ flex: 1, minWidth: 0, color: c.foreground, fontSize: dense ? 15 : 13, paddingVertical: 0, ...(Platform.OS === "web" ? { outlineStyle: "none" } as object : {}) }} />
164
+ {trailing}
156
165
  {count !== undefined ? !!count && <Text accessibilityLiveRegion="polite" style={{ color: c.foregroundMuted, fontSize: dense ? 13 : 12, fontVariant: ["tabular-nums"] }}>{count}</Text>
157
166
  : !!value && <Pressable accessibilityRole="button" accessibilityLabel={`Clear ${placeholder.toLowerCase()}`} hitSlop={dense ? 14 : 8} onPress={() => { onChange(""); inputRef.current?.focus(); }}>
158
167
  <Icon name="X" size={dense ? 16 : 13} color={c.foregroundMuted} />
@@ -171,6 +180,11 @@ export function QueryField({ theme, value, onChange, placeholder, icon, dense, i
171
180
  export function SearchField({ theme, omnibox, dense, onEnter, anywhereKey }: { theme: Theme; omnibox: Omnibox; dense: boolean; onEnter: (item: OmniboxItem | null) => void; anywhereKey?: string | null }) {
172
181
  const { query, setQuery, results, active, move, inputRef, askOn } = omnibox;
173
182
  const placeholder = askOn ? dense ? "Search or ask the Overseer" : "Search, or ask the Overseer" : "Search workspaces, branches, PRs";
183
+ // The bar stays one line: a paste or drop lands here, and Home draws the thumbnails on their own line under it.
184
+ if (askOn) return <ImageField model={omnibox.images} theme={theme} compact={dense} row={false} attach="inline" style={{ flex: 1, minWidth: 0 }}><QueryField theme={theme} onLayoutQuery={omnibox.setPhysical} value={query} onChange={setQuery} placeholder={placeholder} icon="Search" dense={dense} inputRef={inputRef} slashHint={anywhereKey || "/"}
185
+ trailing={<AttachImageButton model={omnibox.images} theme={theme} compact={dense} label="Add image for the Overseer" />}
186
+ slashTitle={anywhereKey ? `${anywhereKey} from anywhere · / on Home` : "/ focuses the search"}
187
+ onSubmit={() => { const item = results?.[active]; if (item || !query.trim()) onEnter(item ?? null); }} onArrow={move} listKeys={!query.trim()} /></ImageField>;
174
188
  return <QueryField theme={theme} onLayoutQuery={omnibox.setPhysical} value={query} onChange={setQuery} placeholder={placeholder} icon="Search" dense={dense} inputRef={inputRef} slashHint={anywhereKey || "/"}
175
189
  slashTitle={anywhereKey ? `${anywhereKey} from anywhere · / on Home` : "/ focuses the search"}
176
190
  onSubmit={() => { const item = results?.[active]; if (item || !query.trim()) onEnter(item ?? null); }} onArrow={move} listKeys={!query.trim()} />;
@@ -1,5 +1,6 @@
1
1
  import type { DispatchRecord } from "../shared/dispatch";
2
2
  import type { PluginClientContext } from "@getpaseo/plugin/client";
3
+ import type { ImageUpload } from "../shared/images";
3
4
  import { contextAskRpc, contextListRpc, dispatchRecordsRpc, displayFeed, homeFeed, queueNeedsSchema, overseerAskRpc, overseerRestartRpc, overseerStartRpc, overseerStatusRpc, prioritiesRpc, prStatsSettingsRpc, rankNowRpc, rankStatusRpc, usageRpc } from "../shared/contracts";
4
5
  import { openFeed } from "./feeds";
5
6
  import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
@@ -256,7 +257,7 @@ export function createHomeExtras(client: PluginClientContext) {
256
257
  overseer: () => overseer,
257
258
  async startOverseer() { overseer = await client.rpc(overseerStartRpc, {}); emit(); return overseer; },
258
259
  /** Sends the omnibox's ask to the Overseer, starting it on first use. */
259
- async askOverseer(text: string) { overseer = await client.rpc(overseerAskRpc, { text }); emit(); return overseer; },
260
+ async askOverseer(text: string, images?: ImageUpload[]) { overseer = await client.rpc(overseerAskRpc, { text, ...(images?.length ? { images } : {}) }); emit(); return overseer; },
260
261
  /** Settings → Agents changed: a new Overseer on the configured agent, handed the old one's last steps. */
261
262
  async restartOverseer() { overseer = await client.rpc(overseerRestartRpc, {}); emit(); return overseer; },
262
263
  /** Catch up's More context asks and their answers. */