paseo-follow-up 2.2.0-beta.2 → 2.2.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/catch-up.tsx +609 -0
- package/client/home-view.ts +21 -3
- package/client/home.tsx +32 -13
- package/client/questions.tsx +15 -2
- package/index.client.tsx +4 -1
- package/index.server.ts +29 -27
- package/package.json +1 -1
- package/server/agent-actions.ts +3 -3
- package/server/agent-parity.ts +6 -3
- package/server/context-requests.ts +51 -24
- package/shared/catch-up.ts +169 -36
- package/shared/contracts.ts +4 -2
- package/shared/display.ts +7 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
// Catch up: everything in Needs you, one card at a time (docs/design/catch-up.md, docs/needs-you.md#catch-up). It
|
|
2
|
+
// renders the same components the panel and Home use (QuestionBody, NeedsYouList, BriefCard, the permission block), so
|
|
3
|
+
// the answer flow is the shared one, never a fork (one-answer-flow-for-every-question). The deck's order and every
|
|
4
|
+
// move are the pure session in shared/catch-up.ts (context-never-blocks-the-deck, the-card-on-screen-never-moves).
|
|
5
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";
|
|
6
|
+
import { Animated, PanResponder, Platform, View } from "react-native";
|
|
7
|
+
import { Pressable, Text } from "./text";
|
|
8
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
9
|
+
import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/ui";
|
|
10
|
+
import { useQuery } from "@tanstack/react-query";
|
|
11
|
+
import { inboxBriefRpc } from "../shared/contracts";
|
|
12
|
+
import { needsYou } from "../shared/attention";
|
|
13
|
+
import { liveBrief } from "../shared/brief";
|
|
14
|
+
import { age, snoozeUntil } from "../shared/inbox";
|
|
15
|
+
import { laterChoices } from "../shared/row-menu";
|
|
16
|
+
import { errorText } from "../shared/errors";
|
|
17
|
+
import { CATCH_UP_RAIL_DEFAULT, CATCH_UP_RAIL_MAX, CATCH_UP_RAIL_MIN } from "../shared/display";
|
|
18
|
+
import { CATCH_UP_KEYS, CONTEXT_ASKS, MODE, askHeadline, catchUpKey, keyLabel, deckCards, groupOf, nextPos, openInWorkspace, park, prevPos, skipWorkspace, swipeLock, swipeOutcome, settle as settleCard, startSession, statsOf, sync, type ContextRequest, type DeckCard, type Outcome, type Session } from "../shared/catch-up";
|
|
19
|
+
import type { Workspace } from "../shared/model";
|
|
20
|
+
import type { ListWorkspace } from "../shared/list";
|
|
21
|
+
import { bottomInset, Button, focusSoon, IconButton, SubmitScope, text, type Theme } from "./kit";
|
|
22
|
+
import { glyphColor } from "./home-list";
|
|
23
|
+
import { useHomeModel, type HomeSources } from "./home-data";
|
|
24
|
+
import { useInbox } from "./inbox";
|
|
25
|
+
import { QuestionBody, type SendReady } from "./questions";
|
|
26
|
+
import { NeedsYouList } from "./needs-you";
|
|
27
|
+
import { BriefCard, type BriefDeps } from "./brief";
|
|
28
|
+
import { SummaryLine } from "./about";
|
|
29
|
+
import { ReferencesLine } from "./linked";
|
|
30
|
+
import { openRowCopy, useWorkspace } from "./workspace-data";
|
|
31
|
+
import { mergedColor, withAlpha, tint } from "./theme";
|
|
32
|
+
import { RichText } from "./rich-text";
|
|
33
|
+
import { DisplaySplit, PermissionBlock, useAgentLive } from "./home";
|
|
34
|
+
import { DockedPane } from "./docked-pane";
|
|
35
|
+
import { useReducedMotion } from "./motion";
|
|
36
|
+
import { PRIMARY_FORM } from "./dock";
|
|
37
|
+
|
|
38
|
+
/** react-native-web's data attribute, so the option-letter keys find this card's radios. */
|
|
39
|
+
const CARD_MARK = { dataSet: { catchUpCard: "1" } } as object;
|
|
40
|
+
const RAIL_MIN_PX = 240;
|
|
41
|
+
const CARD_MIN_PX = 480;
|
|
42
|
+
|
|
43
|
+
const isMac = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test((navigator as { platform?: string }).platform ?? "");
|
|
44
|
+
|
|
45
|
+
export type CatchUpDeps = { sources: HomeSources; briefDeps: BriefDeps; openHome(): void; openPanel(workspaceId: string): void };
|
|
46
|
+
type Nav = { openAgent(a: { agentId: string }): void; openWorkspace(a: { workspaceId: string }): void } | undefined;
|
|
47
|
+
|
|
48
|
+
/** One card's label in the queue rail and in a More context ask: "Q1 · Retry declined cards?", "Merge #255". */
|
|
49
|
+
export function cardLabel(card: DeckCard, w: ListWorkspace | undefined): string {
|
|
50
|
+
if (card.kind === "permission") return "Permission";
|
|
51
|
+
if (card.kind === "question") { const q = w?.questions.find(x => x.id === card.questionId); return q ? `${q.id} · ${q.title}` : card.questionId ?? "Question"; }
|
|
52
|
+
if (card.kind === "item" && card.item) return card.item.title;
|
|
53
|
+
if (card.kind === "brief") return card.s.line || card.s.word || "Ask";
|
|
54
|
+
return card.s.line || "Finished";
|
|
55
|
+
}
|
|
56
|
+
/** The card's own word: a workspace row's word names its first item, the card names its own. */
|
|
57
|
+
function cardWord(card: DeckCard): string {
|
|
58
|
+
if (card.kind === "permission") return "Permission";
|
|
59
|
+
if (card.kind === "question") return card.item?.kind === "question" && card.item.state === "stopped" ? "Agent stopped" : "Question";
|
|
60
|
+
if (card.kind === "finished") return "Finished";
|
|
61
|
+
if (card.kind === "brief") return card.s.word ?? "Ask";
|
|
62
|
+
switch (card.item?.kind) {
|
|
63
|
+
case "merge": return "Merge"; case "reviewers": return "Add reviewers"; case "send": return "Send"; case "answer": return "Your answer";
|
|
64
|
+
case "hold": return "Paused"; case "retry": case "capped": case "message": return "Retry"; case "check": return "Check"; case "decision": return "Blocked";
|
|
65
|
+
default: return card.s.word ?? "Needs you";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const cardIcon = (card: DeckCard) => card.kind === "permission" ? "ShieldQuestion" : card.kind === "question" ? "MessageCircleQuestion"
|
|
69
|
+
: card.item?.kind === "merge" ? "GitMerge" : card.item?.kind === "reviewers" ? "UserPlus" : card.item?.kind === "send" ? "Send" : card.kind === "finished" ? "Flag" : card.s.icon;
|
|
70
|
+
/**
|
|
71
|
+
* The card Skip names what it skips, so it never reads as the workspace (Tom, beta.3: "at first I thought it skips the
|
|
72
|
+
* workspace"): the card's kind where one word says it, else "card", the deck's own word ("N skipped" counts cards).
|
|
73
|
+
*/
|
|
74
|
+
export function skipNoun(card: Pick<DeckCard, "kind" | "item">): string {
|
|
75
|
+
return card.kind === "question" ? "question" : card.kind === "permission" ? "permission" : card.item?.kind === "merge" ? "merge" : "card";
|
|
76
|
+
}
|
|
77
|
+
/** The card Skip's tooltip and accessible name: what it does and that the card comes back. */
|
|
78
|
+
export const skipCardHint = (noun: string) => `Skip this ${noun}. It comes back after the rest`;
|
|
79
|
+
export const skipWorkspaceHint = (n: number) => `Skip this workspace's ${n} cards. They come back after the rest`;
|
|
80
|
+
/** The newest ask about this card, if any. */
|
|
81
|
+
const askFor = (context: readonly ContextRequest[], key: string) => [...context].reverse().find(r => r.cardKey === key) ?? null;
|
|
82
|
+
|
|
83
|
+
export function CatchUp({ theme, compact, deps, navigation, onExit }: { theme: Theme; compact: boolean; deps: CatchUpDeps; navigation: Nav; onExit: () => void }) {
|
|
84
|
+
const c = theme.colors; const t = text(c, compact);
|
|
85
|
+
const { inbox, live, extras } = deps.sources;
|
|
86
|
+
const model = useHomeModel(deps.sources);
|
|
87
|
+
const rows = useInbox(inbox, () => inbox.rows());
|
|
88
|
+
const version = useSyncExternalStore(live.subscribe, live.version, live.version);
|
|
89
|
+
const context = useSyncExternalStore(extras.subscribe, extras.context, extras.context);
|
|
90
|
+
// Everything comes from what the client already holds: Home's model, the inbox rows, the listed workspaces.
|
|
91
|
+
const liveCards = useMemo(() => deckCards({ model, rows, items: id => { const w = live.get(id); return w ? needsYou(w as unknown as Workspace) : []; } }),
|
|
92
|
+
[model, rows, version, live]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
93
|
+
const byKey = useMemo(() => new Map(liveCards.map(x => [x.key, x])), [liveCards]);
|
|
94
|
+
// A card that left Needs you keeps its last copy, so it can say "Handled elsewhere" in place.
|
|
95
|
+
const seen = useRef(new Map<string, DeckCard>());
|
|
96
|
+
for (const card of liveCards) seen.current.set(card.key, card);
|
|
97
|
+
const cardOf = (k: string | undefined) => k ? byKey.get(k) ?? seen.current.get(k) ?? null : null;
|
|
98
|
+
|
|
99
|
+
const [session, setSession] = useState<Session>(() => startSession(liveCards));
|
|
100
|
+
const settled = (id: string) => { const r = context.find(x => x.id === id); return !r || r.state !== "asking"; };
|
|
101
|
+
useEffect(() => { setSession(s => s.order.length || !liveCards.length ? sync(s, liveCards, settled) : startSession(liveCards)); },
|
|
102
|
+
[liveCards, context]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
103
|
+
// Opening and each move read the asks once: a 0.15 host (no feed) is never stale for long, and nothing polls.
|
|
104
|
+
useEffect(() => { void extras.refreshContext(); }, [session.pos]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
105
|
+
|
|
106
|
+
const [more, setMore] = useState(false);
|
|
107
|
+
const key = session.order[session.pos];
|
|
108
|
+
const card = cardOf(key);
|
|
109
|
+
const gone = !!key && session.outcomes[key] === "gone";
|
|
110
|
+
const finished = session.pos >= session.order.length;
|
|
111
|
+
const settle = (outcome: Outcome) => { setMore(false); setSession(s => settleCard(s, outcome)); };
|
|
112
|
+
const skip = () => settle("skipped");
|
|
113
|
+
const skipWs = () => { setMore(false); setSession(skipWorkspace); };
|
|
114
|
+
const wsLeft = openInWorkspace(session).length;
|
|
115
|
+
const back = () => { setMore(false); setSession(s => ({ ...s, pos: prevPos(s) })); };
|
|
116
|
+
const jump = (i: number) => { setMore(false); setSession(s => ({ ...s, pos: i })); };
|
|
117
|
+
const w = card?.s.workspaceId ? live.get(card.s.workspaceId) : undefined;
|
|
118
|
+
// The next card's workspace detail is read while this one is on screen, so it paints at once (prefetch, no poll).
|
|
119
|
+
const nextCard = cardOf(session.order[session.pos + 1]);
|
|
120
|
+
useWorkspace(live, nextCard?.s.workspaceId ?? "", { enabled: !!nextCard?.s.workspaceId });
|
|
121
|
+
|
|
122
|
+
const ask = async (words: string) => {
|
|
123
|
+
if (!card) return;
|
|
124
|
+
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 });
|
|
125
|
+
setMore(false);
|
|
126
|
+
// context-never-blocks-the-deck: the workstream waits, the deck moves on.
|
|
127
|
+
if (out.request.state === "asking") setSession(s => park(s, out.request.id, card.key));
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Desktop keys (CATCH_UP_KEYS, catchUpKey in shared/catch-up.ts): every move has one. The card's controls are found
|
|
131
|
+
// by the names they already carry (option letters, Later (L), Open chat (O)), so a key does exactly what a click does.
|
|
132
|
+
const [keysOpen, setKeysOpen] = useState(false);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (Platform.OS !== "web" || compact) return;
|
|
135
|
+
type Ev = { key: string; metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean; isComposing: boolean; target: unknown; preventDefault(): void };
|
|
136
|
+
type El = { tagName?: string; isContentEditable?: boolean; click?(): void; focus?(): void; closest?(q: string): El | null };
|
|
137
|
+
type Doc = { querySelector(q: string): El | null; querySelectorAll(q: string): ArrayLike<El>; activeElement?: El | null; addEventListener(t: string, f: (e: Ev) => void): void; removeEventListener(t: string, f: (e: Ev) => void): void };
|
|
138
|
+
const doc = (globalThis as { document?: Doc }).document; if (!doc) return;
|
|
139
|
+
const mac = isMac();
|
|
140
|
+
const inCard = (q: string) => doc.querySelector(`[data-catch-up-card] ${q}`);
|
|
141
|
+
const railItems = () => Array.from(doc.querySelectorAll("[data-catch-up-rail] [role=\"button\"]"));
|
|
142
|
+
const onKey = (e: Ev) => {
|
|
143
|
+
const el = e.target as El | null;
|
|
144
|
+
const typing = !!el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || !!el.isContentEditable);
|
|
145
|
+
const hit = catchUpKey({ key: e.key, meta: e.metaKey, ctrl: e.ctrlKey, alt: e.altKey, shift: e.shiftKey, composing: e.isComposing, mac },
|
|
146
|
+
{ typing, inMore: !!el?.closest?.("[data-catch-up-more]"), moreOpen: more, inRail: !!el?.closest?.("[data-catch-up-rail]") });
|
|
147
|
+
if (!hit || finished && !["back", "keys", "leave", "rail"].includes(hit.action)) return;
|
|
148
|
+
const click = (q: string) => { const b = doc.querySelector(q); b?.click?.(); return !!b; };
|
|
149
|
+
switch (hit.action) {
|
|
150
|
+
case "skip": skip(); break;
|
|
151
|
+
case "skip-workspace": if (wsLeft < 2) return; skipWs(); break;
|
|
152
|
+
case "back": back(); break;
|
|
153
|
+
case "more": if (!click('[data-catch-up-card-moves] [aria-label="More context"]')) setMore(v => !v); break;
|
|
154
|
+
case "keys": setKeysOpen(v => !v); break;
|
|
155
|
+
case "leave": onExit(); break;
|
|
156
|
+
case "pick": inCard(`[role="radio"][aria-label^="${hit.arg}. "]`)?.click?.(); break;
|
|
157
|
+
case "own": inCard('[role="radio"][aria-label^="Something else"]')?.click?.(); break;
|
|
158
|
+
case "send": { const b = inCard('[aria-label^="Send your"]') ?? inCard('[aria-label^="Send "]'); if (!b) return; b.click?.(); break; }
|
|
159
|
+
case "note": { const add = inCard('[aria-label^="Add a note"]'); if (add) add.click?.(); else doc.querySelector('[aria-label="Tell the agent something"]')?.focus?.(); break; }
|
|
160
|
+
// Its sheet or popover takes focus itself (MoveResult).
|
|
161
|
+
case "later": if (!click('[aria-label="Later (L)"]')) return; break;
|
|
162
|
+
case "chat": if (!click('[aria-label="Open chat (O)"]')) return; break;
|
|
163
|
+
case "chip": doc.querySelectorAll("[data-catch-up-more] [role=\"radio\"]")[Number(hit.arg) - 1]?.click?.(); break;
|
|
164
|
+
case "ask": if (!click('[data-catch-up-more] [data-ask-agent] [role="button"]')) return; break;
|
|
165
|
+
case "rail": {
|
|
166
|
+
const items = railItems();
|
|
167
|
+
if (el?.closest?.("[data-catch-up-rail]")) { (el as { blur?(): void }).blur?.(); break; }
|
|
168
|
+
(doc.querySelector("[data-catch-up-rail] [data-catch-up-here]") ?? items[0])?.focus?.();
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case "rail-up": case "rail-down": {
|
|
172
|
+
const items = railItems(); const i = items.indexOf(el as El);
|
|
173
|
+
items[Math.max(0, Math.min(items.length - 1, i + (hit.action === "rail-up" ? -1 : 1)))]?.focus?.();
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
default: return;
|
|
177
|
+
}
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
};
|
|
180
|
+
doc.addEventListener("keydown", onKey);
|
|
181
|
+
return () => doc.removeEventListener("keydown", onKey);
|
|
182
|
+
});
|
|
183
|
+
// Phones: the card follows the finger (Paseo's sidebar drag): left skips this card, right goes Back, the card about to
|
|
184
|
+
// show peeks underneath, and a drag held halfway stays there. The direction locks in the first SWIPE_LOCK_PX, so a
|
|
185
|
+
// vertical scroll stays a scroll. Answers are never a swipe: a stray thumb must not decide anything. Reduced motion:
|
|
186
|
+
// no follow, just the move on release. Transforms only (translateX), on the native driver where there is one.
|
|
187
|
+
const reduced = useReducedMotion();
|
|
188
|
+
const drag = useRef(new Animated.Value(0)).current;
|
|
189
|
+
const [dragDir, setDragDir] = useState<"skip" | "back" | null>(null);
|
|
190
|
+
const width = useRef(390);
|
|
191
|
+
const lock = useRef<"x" | "y" | null>(null);
|
|
192
|
+
// The finger's own offset from where it went down: react-native-web's accumulated gestureState.dx runs ahead of a
|
|
193
|
+
// mouse drag, so the card would outrun the pointer. Every touch start passes the capture phase, so it is read there.
|
|
194
|
+
const origin = useRef({ x: 0, y: 0 });
|
|
195
|
+
type Touch = { nativeEvent: { pageX: number; pageY: number } };
|
|
196
|
+
const offset = (e: Touch) => ({ dx: e.nativeEvent.pageX - origin.current.x, dy: e.nativeEvent.pageY - origin.current.y });
|
|
197
|
+
const canBack = session.pos > 0;
|
|
198
|
+
const pan = useMemo(() => PanResponder.create({
|
|
199
|
+
onStartShouldSetPanResponderCapture: e => { origin.current = { x: e.nativeEvent.pageX, y: e.nativeEvent.pageY }; lock.current = null; return false; },
|
|
200
|
+
onMoveShouldSetPanResponderCapture: e => {
|
|
201
|
+
if (!compact || finished) return false;
|
|
202
|
+
const { dx, dy } = offset(e);
|
|
203
|
+
const l = swipeLock(dx, dy);
|
|
204
|
+
if (!l) return false;
|
|
205
|
+
lock.current ??= l;
|
|
206
|
+
return lock.current === "x";
|
|
207
|
+
},
|
|
208
|
+
onPanResponderTerminationRequest: () => false,
|
|
209
|
+
onPanResponderMove: e => {
|
|
210
|
+
const { dx } = offset(e);
|
|
211
|
+
setDragDir(dx < 0 ? "skip" : canBack ? "back" : null);
|
|
212
|
+
// Nothing behind the first card: the drag resists instead of revealing an empty space.
|
|
213
|
+
if (!reduced) drag.setValue(dx > 0 && !canBack ? dx * 0.25 : dx);
|
|
214
|
+
},
|
|
215
|
+
onPanResponderRelease: (e, g) => {
|
|
216
|
+
lock.current = null;
|
|
217
|
+
const out = swipeOutcome({ dx: offset(e).dx, vx: g.vx, width: width.current, canBack });
|
|
218
|
+
const act = () => { drag.setValue(0); setDragDir(null); if (out === "skip") skip(); else if (out === "back") back(); };
|
|
219
|
+
if (out === "stay") { setDragDir(null); if (!reduced) Animated.spring(drag, { toValue: 0, bounciness: 0, speed: 20, useNativeDriver: Platform.OS !== "web" }).start(); else drag.setValue(0); return; }
|
|
220
|
+
if (reduced) { act(); return; }
|
|
221
|
+
Animated.timing(drag, { toValue: (out === "skip" ? -1 : 1) * width.current, duration: 160, useNativeDriver: Platform.OS !== "web" }).start(act);
|
|
222
|
+
},
|
|
223
|
+
onPanResponderTerminate: () => { lock.current = null; setDragDir(null); drag.setValue(0); },
|
|
224
|
+
}), [compact, key, finished, canBack, reduced]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
225
|
+
|
|
226
|
+
const stats = statsOf(session);
|
|
227
|
+
const total = session.order.length;
|
|
228
|
+
const waitingChip = stats.waiting > 0 && <View accessibilityLabel={`${MODE.waiting(stats.waiting)}. They come back as the next card when the answer is ready; Back reaches them any time.`}
|
|
229
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 4, paddingHorizontal: 8, height: 22, borderRadius: 11, backgroundColor: c.surface2 }}>
|
|
230
|
+
<Icon name="Hourglass" size={11} color={c.foregroundMuted} /><Text style={[t.small, { fontWeight: "600" }]}>{MODE.waiting(stats.waiting)}</Text>
|
|
231
|
+
</View>;
|
|
232
|
+
const progress = <View style={{ gap: 6, paddingHorizontal: compact ? 16 : 20, paddingTop: compact ? 8 : 14, paddingBottom: 10 }}>
|
|
233
|
+
<View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap", gap: 8, minHeight: compact ? 44 : 32 }}>
|
|
234
|
+
{/* Phones: the host header's ← is the only back control (DESIGN.md "One header"). */}
|
|
235
|
+
{!compact && <IconButton theme={theme} compact={compact} icon="X" label={`Leave ${MODE.name} (X)`} tooltip onPress={onExit} />}
|
|
236
|
+
<Text accessibilityRole="header" style={[t.title, { flex: 1 }]}>{finished || !total ? MODE.name : <>{MODE.name} <Text style={{ color: c.foregroundMuted, fontWeight: "400", fontVariant: ["tabular-nums"] }}>{MODE.progress(session.pos + 1, total).slice(MODE.name.length + 1)}</Text></>}</Text>
|
|
237
|
+
{waitingChip}
|
|
238
|
+
{!compact && <Pressable accessibilityRole="button" accessibilityLabel="Show the keys (S)" onPress={() => setKeysOpen(v => !v)}><Text style={t.small}>{finished ? "S keys · X leave" : "J skip card · ⇧J skip workspace · K back · M more context · S keys"}</Text></Pressable>}
|
|
239
|
+
</View>
|
|
240
|
+
{/* One segment per card: done in the foreground colour, skipped hollow, waiting for context amber-tinted, the current one amber. */}
|
|
241
|
+
{total > 0 && <View accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ flexDirection: "row", gap: 3 }}>
|
|
242
|
+
{total > 24 ? <View style={{ flex: 1, height: 4, borderRadius: 2, backgroundColor: c.border }}><View style={{ width: `${Math.round(100 * (stats.done + stats.later + stats.gone) / total)}%`, height: 4, borderRadius: 2, backgroundColor: c.foreground }} /></View>
|
|
243
|
+
: session.order.map((k, i) => {
|
|
244
|
+
const o = session.outcomes[k];
|
|
245
|
+
const waiting = !o && !!session.parked[groupOf(k)];
|
|
246
|
+
const bg = i === session.pos && !finished ? c.statusWarning : o === "done" || o === "later" ? c.foreground : o ? withAlpha(c.foreground, 0.35) : waiting ? withAlpha(c.statusWarning, 0.4) : c.border;
|
|
247
|
+
return <View key={k} style={{ flex: 1, height: 4, borderRadius: 2, backgroundColor: bg }} />;
|
|
248
|
+
})}
|
|
249
|
+
</View>}
|
|
250
|
+
</View>;
|
|
251
|
+
|
|
252
|
+
const body = finished || !card ? <Finished theme={theme} compact={compact} stats={stats} empty={!total} onHome={onExit}
|
|
253
|
+
onSkipped={() => setSession(s => ({ ...s, pos: s.order.findIndex(k => s.outcomes[k] === "skipped"), lapped: true }))} />
|
|
254
|
+
: <CardView key={card.key} card={card} w={w} theme={theme} compact={compact} deps={deps} navigation={navigation} gone={gone} more={more} setMore={setMore}
|
|
255
|
+
request={askFor(context, card.key)} waiting={!!session.parked[card.s.key]} onAsk={ask}
|
|
256
|
+
sameWorkspace={session.order.filter(k => cardOf(k)?.s.key === card.s.key)}
|
|
257
|
+
onDone={() => settle("done")} onSkip={skip} onSkipWorkspace={wsLeft > 1 ? skipWs : undefined} wsLeft={wsLeft} onBack={session.pos > 0 ? back : undefined} onLater={() => settle("later")} />;
|
|
258
|
+
|
|
259
|
+
const rail = <ScrollView {...({ dataSet: { catchUpRail: "1" } } as object)} contentContainerStyle={{ paddingVertical: 8 }}>
|
|
260
|
+
{session.order.map((k, i) => {
|
|
261
|
+
const x = cardOf(k); if (!x) return null;
|
|
262
|
+
const xw = x.s.workspaceId ? live.get(x.s.workspaceId) : undefined;
|
|
263
|
+
const o = session.outcomes[k]; const here = i === session.pos;
|
|
264
|
+
const waiting = !o && !!session.parked[x.s.key];
|
|
265
|
+
const firstOfWs = i === 0 || cardOf(session.order[i - 1])?.s.key !== x.s.key;
|
|
266
|
+
const label = cardLabel(x, xw);
|
|
267
|
+
return <View key={k}>
|
|
268
|
+
{firstOfWs && <Text numberOfLines={1} style={[t.small, { paddingHorizontal: 16, paddingTop: i ? 10 : 2, paddingBottom: 2, fontWeight: "600" }]}>{x.s.title}</Text>}
|
|
269
|
+
<Pressable {...({ dataSet: here ? { catchUpHere: "1" } : {} } as object)} accessibilityRole="button" accessibilityState={{ selected: here }} accessibilityLabel={`${label}${o ? `, ${o === "gone" ? "handled elsewhere" : o}` : waiting ? ", getting context" : ""}`} onPress={() => jump(i)}
|
|
270
|
+
style={state => ({ flexDirection: "row", alignItems: "center", gap: 8, minHeight: 32, paddingHorizontal: 16, backgroundColor: here ? c.surface2 : (state as { hovered?: boolean }).hovered ? c.surface1 : "transparent",
|
|
271
|
+
borderLeftWidth: 2, borderLeftColor: here ? c.statusWarning : "transparent" })}>
|
|
272
|
+
<Icon name={o === "done" ? "CircleCheck" : o === "skipped" ? "CornerUpRight" : o === "later" ? "AlarmClock" : o === "gone" ? "CircleCheck" : waiting ? "Hourglass" : cardIcon(x)} size={13}
|
|
273
|
+
color={o === "done" || o === "gone" ? c.statusSuccess : o || waiting ? c.foregroundMuted : glyphColor(x.s, c, false)} />
|
|
274
|
+
<Text numberOfLines={1} style={[t.meta, { flex: 1, color: o ? c.foregroundMuted : c.foreground, textDecorationLine: o === "done" ? "line-through" : "none" }]}>{label}</Text>
|
|
275
|
+
</Pressable>
|
|
276
|
+
</View>;
|
|
277
|
+
})}
|
|
278
|
+
</ScrollView>;
|
|
279
|
+
|
|
280
|
+
// Under the dragged card: the one the release would show, so the drag says where it goes.
|
|
281
|
+
const peekKey = dragDir === "skip" ? session.order[nextPos(session, session.pos)] : dragDir === "back" ? session.order[prevPos(session)] : undefined;
|
|
282
|
+
const peekCard = cardOf(peekKey);
|
|
283
|
+
const peek = compact && dragDir && <View accessibilityElementsHidden importantForAccessibility="no-hide-descendants" pointerEvents="none"
|
|
284
|
+
style={{ position: "absolute", top: 0, bottom: 0, left: 0, right: 0, backgroundColor: c.surface1, justifyContent: "center", alignItems: dragDir === "skip" ? "flex-end" : "flex-start", paddingHorizontal: 20 }}>
|
|
285
|
+
<View style={{ maxWidth: "42%", gap: 4, alignItems: dragDir === "skip" ? "flex-end" : "flex-start" }}>
|
|
286
|
+
<Icon name={dragDir === "skip" ? "ArrowRight" : "ChevronLeft"} size={18} color={c.foregroundMuted} />
|
|
287
|
+
<Text style={[t.small, { fontWeight: "600" }]}>{dragDir === "skip" ? `Skip ${card ? skipNoun(card) : "card"}` : "Back"}</Text>
|
|
288
|
+
<Text numberOfLines={2} style={[t.meta, { textAlign: dragDir === "skip" ? "right" : "left" }]}>{peekCard ? `${peekCard.s.title} · ${cardLabel(peekCard, peekCard.s.workspaceId ? live.get(peekCard.s.workspaceId) : undefined)}` : MODE.endOfDeck}</Text>
|
|
289
|
+
</View>
|
|
290
|
+
</View>;
|
|
291
|
+
const main = <View style={{ flex: 1, minWidth: 0, overflow: "hidden" }} onLayout={e => { width.current = e.nativeEvent.layout.width; }} {...pan.panHandlers}>
|
|
292
|
+
{peek}
|
|
293
|
+
<Animated.View {...({ dataSet: { catchUpDrag: "1" } } as object)} style={{ flex: 1, backgroundColor: c.surface0, transform: [{ translateX: drag }],
|
|
294
|
+
...(dragDir ? { shadowColor: "#000", shadowOpacity: 0.18, shadowRadius: 12, shadowOffset: { width: 0, height: 0 } } : {}) }}>{body}</Animated.View>
|
|
295
|
+
</View>;
|
|
296
|
+
return <View style={{ flex: 1, backgroundColor: c.surface0 }}>
|
|
297
|
+
{progress}
|
|
298
|
+
<View style={{ flex: 1, borderTopWidth: 1, borderTopColor: c.border }}>
|
|
299
|
+
{/* Desktop: the queue rail beside the card, resizable (side-panes-are-resizable); its width is the Display field catch_up_rail_fraction. */}
|
|
300
|
+
{keysOpen && !compact && <KeysSheet theme={theme} onClose={() => setKeysOpen(false)} />}
|
|
301
|
+
{!compact && total > 0 && !finished
|
|
302
|
+
? <DisplaySplit theme={theme} main={main} side={rail} field="catch_up_rail_fraction" testID="follow-up-catch-up-split" label="Resize the queue"
|
|
303
|
+
defaultFraction={CATCH_UP_RAIL_DEFAULT} range={[CATCH_UP_RAIL_MIN, CATCH_UP_RAIL_MAX]} minSide={RAIL_MIN_PX} minMain={CARD_MIN_PX} />
|
|
304
|
+
: main}
|
|
305
|
+
</View>
|
|
306
|
+
</View>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** One card: who and what, the ask through its own surface's component, then the deck's moves pinned to the bottom. */
|
|
310
|
+
function CardView({ card, w, theme, compact, deps, navigation, gone, more, setMore, request, waiting, onAsk, sameWorkspace, onDone, onSkip, onSkipWorkspace, wsLeft, onBack, onLater }: {
|
|
311
|
+
card: DeckCard; w: ListWorkspace | undefined; theme: Theme; compact: boolean; deps: CatchUpDeps; navigation: Nav; gone: boolean; more: boolean; setMore: (v: boolean | ((v: boolean) => boolean)) => void;
|
|
312
|
+
request: ContextRequest | null; waiting: boolean; onAsk: (words: string) => Promise<void>;
|
|
313
|
+
sameWorkspace: string[]; onDone: () => void; onSkip: () => void; onSkipWorkspace?: () => void; wsLeft: number; onBack?: () => void; onLater: () => void;
|
|
314
|
+
}) {
|
|
315
|
+
const c = theme.colors; const t = text(c, compact);
|
|
316
|
+
const s = card.s;
|
|
317
|
+
const { workspace: full } = useWorkspace(deps.sources.live, s.workspaceId ?? "");
|
|
318
|
+
const ws = openRowCopy<ListWorkspace>(w, full);
|
|
319
|
+
const [laterOpen, setLaterOpen] = useState(false);
|
|
320
|
+
const [ready, setReady] = useState<SendReady | null>(null);
|
|
321
|
+
const openChat = () => { if (!navigation) return; if (s.agentId) navigation.openAgent({ agentId: s.agentId }); else if (s.workspaceId) navigation.openWorkspace({ workspaceId: s.workspaceId }); };
|
|
322
|
+
const word = cardWord(card);
|
|
323
|
+
const color = card.item?.kind === "merge" ? mergedColor(c) : card.kind === "finished" ? c.foregroundMuted : c.statusWarning;
|
|
324
|
+
const q = card.kind === "question" ? ws?.questions.find(x => x.id === card.questionId) ?? null : null;
|
|
325
|
+
const nth = sameWorkspace.indexOf(card.key);
|
|
326
|
+
const agentName = s.agent ?? "the agent";
|
|
327
|
+
const noun = skipNoun(card);
|
|
328
|
+
|
|
329
|
+
const head = <View style={{ gap: 6 }}>
|
|
330
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
|
|
331
|
+
<Icon name={cardIcon(card)} size={14} color={color} />
|
|
332
|
+
<Text numberOfLines={1} style={[t.meta, { flex: 1 }]}>
|
|
333
|
+
<Text style={{ color, fontWeight: "600" }}>{word}</Text>
|
|
334
|
+
{[s.at ? `${age(s.at, Date.now())} ago` : "", s.project].filter(Boolean).map(x => ` · ${x}`).join("")}
|
|
335
|
+
{sameWorkspace.length > 1 ? ` · ${nth + 1} of ${sameWorkspace.length} here` : ""}
|
|
336
|
+
</Text>
|
|
337
|
+
</View>
|
|
338
|
+
<Text accessibilityRole="header" numberOfLines={2} style={compact ? t.title : [t.title, { fontSize: 17, lineHeight: 23 }]}>{s.title}{s.agent ? <Text style={{ color: c.foregroundMuted, fontWeight: "400" }}>{` › ${s.agent}`}</Text> : null}</Text>
|
|
339
|
+
{ws && <SummaryLine key={ws.id} workspace={ws} theme={theme} compact={compact} />}
|
|
340
|
+
{full && <ReferencesLine workspace={full} theme={theme} compact={compact} />}
|
|
341
|
+
</View>;
|
|
342
|
+
|
|
343
|
+
const goneBanner = gone && <View accessibilityRole="alert" style={{ flexDirection: "row", alignItems: "center", gap: 8, padding: 12, borderRadius: 10, backgroundColor: c.surface1, borderWidth: 1, borderColor: c.border }}>
|
|
344
|
+
<Icon name="CircleCheck" size={16} color={c.statusSuccess} />
|
|
345
|
+
<Text style={[t.body, { flex: 1 }]}>Handled elsewhere. Nothing left to do here.</Text>
|
|
346
|
+
<Button theme={theme} compact={compact} kind="primary" icon="ArrowRight" title="Next" onPress={onSkip} />
|
|
347
|
+
</View>;
|
|
348
|
+
|
|
349
|
+
const askBlock = card.kind === "question" && q && ws
|
|
350
|
+
? <View style={{ gap: 8 }}>
|
|
351
|
+
<RichText plain style={compact ? t.ask : [t.body, { fontSize: 15, lineHeight: 21, fontWeight: "600" }]}>{`${q.id} · ${q.title}`}</RichText>
|
|
352
|
+
<QuestionBody key={q.id} workspace={ws} question={q} theme={theme} compact={compact} inline={false}
|
|
353
|
+
openAgent={id => navigation?.openAgent({ agentId: id })} onAnswered={onDone} onSendReady={setReady} />
|
|
354
|
+
</View>
|
|
355
|
+
: card.kind === "item" && card.item && full
|
|
356
|
+
? <View style={{ borderRadius: 10, borderWidth: 1, borderColor: withAlpha(c.statusWarning, 0.45), overflow: "hidden" }}>
|
|
357
|
+
<NeedsYouList workspace={full} theme={theme} compact={compact} rows={[card.item]} flush actions={{ after: onDone, openAgent: openChat } as never} />
|
|
358
|
+
</View>
|
|
359
|
+
: card.kind === "permission" ? <PermissionCard s={s} theme={theme} compact={compact} onDone={onDone} />
|
|
360
|
+
: card.kind === "brief" ? <BriefAsk s={s} theme={theme} compact={compact} deps={deps} />
|
|
361
|
+
: <View style={{ gap: 10 }}>
|
|
362
|
+
<Text style={compact ? t.ask : [t.body, { fontSize: 15, lineHeight: 21, fontWeight: "600" }]}>{s.line || "The agent finished its turn."}</Text>
|
|
363
|
+
<Text style={t.meta}>Nothing to decide. Sign it off once you've read it, or reply.</Text>
|
|
364
|
+
<View style={{ flexDirection: "row", gap: 8 }}><Button theme={theme} compact={compact} grow={compact} kind="primary" icon="Check" title="Sign off" onPress={() => { if (s.agentId) void deps.sources.inbox.signOff([s.agentId]); onDone(); }} /></View>
|
|
365
|
+
</View>;
|
|
366
|
+
|
|
367
|
+
// Add context without answering: every card that isn't a question has the agent's reply box (a question has its note).
|
|
368
|
+
const reply = card.kind !== "question" && s.agentId && <NoteRow theme={theme} compact={compact} agentId={s.agentId} />;
|
|
369
|
+
const contextBlock = request && <ContextAnswer theme={theme} compact={compact} request={request} waiting={waiting} agent={agentName} openChat={openChat} openAgent={navigation ? id => navigation.openAgent({ agentId: id }) : undefined} />;
|
|
370
|
+
// a-move-bar-action-opens-in-view (MOVE_OPENS): More context and Later open where the eye is, a sheet above the
|
|
371
|
+
// phone's bar or a popover on their button on desktop, never appended below the card.
|
|
372
|
+
const closeMore = () => { setMore(false); if (!compact) focusSoon("catch-up-more"); };
|
|
373
|
+
const moreBlock = more && <MorePanel theme={theme} compact={compact} onClose={closeMore} onAsk={onAsk} />;
|
|
374
|
+
const later = (until: string) => { setLaterOpen(false); if (s.agentId) void deps.sources.inbox.snooze([s.agentId], until); onLater(); };
|
|
375
|
+
const laterBlock = laterOpen && <View {...({ dataSet: { catchUpLater: "1" } } as object)} accessibilityRole="menu" accessibilityLabel="Later" style={{ gap: 8 }}>
|
|
376
|
+
<Text style={[t.small, { fontWeight: "600" }]}>Back in your Needs you</Text>
|
|
377
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8 }}>
|
|
378
|
+
{laterChoices(new Date()).map(([k, label]) => <Button key={k} theme={theme} compact={compact} kind="ghost" icon="AlarmClock" title={label} onPress={() => later(snoozeUntil(k, new Date()))} />)}
|
|
379
|
+
</View>
|
|
380
|
+
</View>;
|
|
381
|
+
const toggleMore = () => { setLaterOpen(false); setMore(v => !v); };
|
|
382
|
+
const toggleLater = () => { setMore(false); setLaterOpen(v => !v); };
|
|
383
|
+
const popover = (open: ReactNode, label: string, width: number) => open && <MoveResult place="popover" theme={theme} label={label} width={width}>{open}</MoveResult>;
|
|
384
|
+
|
|
385
|
+
// The deck's moves: in thumb reach on phones, under the card on desktop. Once the card has an answer to send, Send to
|
|
386
|
+
// agent takes the bar's primary slot: the question's own Send (onSendReady), so one click, one flow. Icon-only moves
|
|
387
|
+
// carry their name for screen readers and as a desktop tooltip.
|
|
388
|
+
const send = ready && (compact
|
|
389
|
+
? <View style={{ flex: 1 }}><Button theme={theme} compact grow kind="primary" icon="Send" title="Send" accessibilityLabel="Send to agent" shortcut disabled={ready.busy} onPress={ready.send} /></View>
|
|
390
|
+
: <Button theme={theme} kind="primary" icon="Send" title="Send to agent" shortcut disabled={ready.busy} onPress={ready.send} />);
|
|
391
|
+
const moves = <View {...({ dataSet: { catchUpCardMoves: "1" } } as object)} style={{ flexDirection: "row", alignItems: "center", gap: 8, paddingHorizontal: compact ? 12 : 0, paddingTop: compact ? 10 : 4 }}>
|
|
392
|
+
<IconButton theme={theme} compact={compact} icon="ChevronLeft" label={compact ? "Back" : "Back (K or ←)"} tooltip={!compact} disabled={!onBack} onPress={() => onBack?.()} />
|
|
393
|
+
{compact ? <IconButton theme={theme} compact icon="Sparkles" label="More context" onPress={toggleMore} />
|
|
394
|
+
: <View>{popover(moreBlock, "More context", 560)}<Tip label="More context (M)"><Button theme={theme} icon="Sparkles" title="More context" accessibilityHint="M" nativeID="catch-up-more" onPress={toggleMore} /></Tip></View>}
|
|
395
|
+
<View>{!compact && popover(laterBlock, "Later", 380)}<IconButton theme={theme} compact={compact} icon="AlarmClock" label={compact ? "Later" : "Later (L)"} tooltip={!compact} disabled={!s.agentId} onPress={toggleLater} /></View>
|
|
396
|
+
<IconButton theme={theme} compact={compact} icon="MessageSquare" label={compact ? "Open chat" : "Open chat (O)"} tooltip={!compact} disabled={!navigation} onPress={openChat} />
|
|
397
|
+
{!compact && <View style={{ flex: 1 }} />}
|
|
398
|
+
{/* Two skips, named apart: this card (J), and the whole workspace (⇧J), shown only while it has more than one card left. */}
|
|
399
|
+
{compact ? ready ? <IconButton theme={theme} compact icon="ArrowRight" label={skipCardHint(noun)} onPress={onSkip} />
|
|
400
|
+
: <View style={{ flex: 1 }}><Button theme={theme} compact grow icon="ArrowRight" title={`Skip ${noun}`} accessibilityLabel={skipCardHint(noun)} onPress={onSkip} /></View>
|
|
401
|
+
: <>
|
|
402
|
+
{onSkipWorkspace && <Tip label={`${skipWorkspaceHint(wsLeft)} (⇧J)`}><Button theme={theme} kind="ghost" icon="ChevronsRight" title="Skip workspace" accessibilityLabel={skipWorkspaceHint(wsLeft)} accessibilityHint="Shift+J" onPress={onSkipWorkspace} /></Tip>}
|
|
403
|
+
<Tip label={`${skipCardHint(noun)} (J or →)`}><Button theme={theme} icon="ArrowRight" title={`Skip ${noun}`} accessibilityLabel={skipCardHint(noun)} accessibilityHint="J" onPress={onSkip} /></Tip>
|
|
404
|
+
</>}
|
|
405
|
+
{send}
|
|
406
|
+
</View>;
|
|
407
|
+
|
|
408
|
+
// a-focused-field-and-its-send-stay-in-view: the phone's bar is DockedPane's dock, so while a field has focus or the
|
|
409
|
+
// keyboard is up the bar steps aside and the field (Something else, a note) keeps its Send in view. An open sheet
|
|
410
|
+
// stays (the pane stops above the keyboard), so More context's ask box and its Ask buttons stay in view too.
|
|
411
|
+
const sheet = compact && (moreBlock || laterBlock);
|
|
412
|
+
return <DockedPane compact={compact}
|
|
413
|
+
contentContainerStyle={{ padding: compact ? 16 : 28, gap: compact ? 16 : 18, ...(compact ? {} : { maxWidth: 720, width: "100%", alignSelf: "center" }) }}
|
|
414
|
+
dock={({ yields, typingInContent }) => compact && (sheet && !typingInContent || !yields) && <View style={[{ borderTopWidth: 1, borderTopColor: c.border, backgroundColor: c.surface0 }, bottomInset(compact)]}>
|
|
415
|
+
{sheet && !typingInContent && <MoveResult place="sheet" theme={theme} label={moreBlock ? "More context" : "Later"}>{sheet}</MoveResult>}
|
|
416
|
+
{!yields && !sheet && onSkipWorkspace && <View style={{ flexDirection: "row", justifyContent: "flex-end", paddingHorizontal: 12, paddingTop: 6 }}>
|
|
417
|
+
<Button theme={theme} compact kind="ghost" icon="ChevronsRight" title={`Skip workspace · ${wsLeft} cards`} accessibilityLabel={skipWorkspaceHint(wsLeft)} onPress={onSkipWorkspace} />
|
|
418
|
+
</View>}
|
|
419
|
+
{!yields && moves}
|
|
420
|
+
</View>}>
|
|
421
|
+
{goneBanner}
|
|
422
|
+
{head}
|
|
423
|
+
{contextBlock}
|
|
424
|
+
<View {...CARD_MARK} style={{ gap: 16 }}>{askBlock}</View>
|
|
425
|
+
{reply}
|
|
426
|
+
{/* Desktop: ⌘↵ anywhere on the bar sends, as the bar's Send says (its own SubmitScope). */}
|
|
427
|
+
{!compact && <SubmitScope enabled={!!ready && !ready.busy} onSubmit={() => ready?.send()}>{moves}</SubmitScope>}
|
|
428
|
+
</DockedPane>;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Where a move's result opens (MOVE_OPENS, a-move-bar-action-opens-in-view): a sheet in the phone's dock or a popover
|
|
433
|
+
* on its desktop button. Focus moves into it (its first choice), and on the web it scrolls into view the least distance.
|
|
434
|
+
*/
|
|
435
|
+
function MoveResult({ place, theme, label, width, children }: { place: "sheet" | "popover"; theme: Theme; label: string; width?: number; children: ReactNode }) {
|
|
436
|
+
const c = theme.colors;
|
|
437
|
+
const ref = useRef<View>(null);
|
|
438
|
+
useEffect(() => {
|
|
439
|
+
if (Platform.OS !== "web") return;
|
|
440
|
+
const t = setTimeout(() => {
|
|
441
|
+
const node = ref.current as unknown as { querySelector?(q: string): { focus?(o?: object): void } | null; scrollIntoView?(o: object): void } | null;
|
|
442
|
+
node?.scrollIntoView?.({ block: "nearest" });
|
|
443
|
+
// The first choice: More context's suggestions ("I don't get it" leads), else Later's first time.
|
|
444
|
+
(node?.querySelector?.('[role="radio"]') ?? node?.querySelector?.('[role="menu"] [role="button"]'))?.focus?.({ preventScroll: true });
|
|
445
|
+
}, 0);
|
|
446
|
+
return () => clearTimeout(t);
|
|
447
|
+
}, []);
|
|
448
|
+
return <View ref={ref} {...({ dataSet: { moveResult: place } } as object)} accessibilityRole={"dialog" as never} accessibilityLabel={label}
|
|
449
|
+
style={[{ padding: place === "sheet" ? 14 : 16, borderRadius: 12, borderWidth: 1, borderColor: c.border, backgroundColor: c.surface1 },
|
|
450
|
+
place === "sheet"
|
|
451
|
+
? { marginHorizontal: 12, marginTop: 12 }
|
|
452
|
+
: { position: "absolute", zIndex: 20, left: 0, bottom: "100%", marginBottom: 8, width, shadowColor: "#000", shadowOpacity: 0.22, shadowRadius: 16, shadowOffset: { width: 0, height: 6 } }]}>
|
|
453
|
+
{children}
|
|
454
|
+
</View>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** What came back for this card: the answer, "answered in its chat", a failure, or (seen going Back) that it's still asking. */
|
|
458
|
+
function ContextAnswer({ theme, compact, request, waiting, agent, openChat, openAgent }: { theme: Theme; compact: boolean; request: ContextRequest; waiting: boolean; agent: string; openChat: () => void; openAgent?: (agentId: string) => void }) {
|
|
459
|
+
const c = theme.colors; const t = text(c, compact);
|
|
460
|
+
const who = request.target === "overseer" ? "Overseer" : agent === "the agent" ? "The agent" : agent;
|
|
461
|
+
const asking = request.state === "asking";
|
|
462
|
+
return <View accessibilityLiveRegion="polite" style={{ gap: 8, padding: compact ? 14 : 16, borderRadius: 12, borderWidth: 1, borderColor: asking ? c.border : withAlpha(c.statusSuccess, 0.4), backgroundColor: c.surface1 }}>
|
|
463
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
464
|
+
<Icon name={asking ? "Hourglass" : request.state === "failed" ? "CircleAlert" : "Sparkles"} size={14} color={request.state === "failed" ? c.statusDanger : c.foregroundMuted} />
|
|
465
|
+
<RichText plain style={[t.small, { flex: 1 }]}>{asking ? `Asked ${who === "Overseer" ? "the Overseer" : who}${waiting ? " · this comes back as the next card when it answers. You can still act on it now" : ""}` : `${who} · you asked: ${askHeadline(request.ask)}`}</RichText>
|
|
466
|
+
</View>
|
|
467
|
+
{request.state === "answered" && request.answer && <RichText selectable style={t.body}>{request.answer}</RichText>}
|
|
468
|
+
{request.state === "chat" && <View style={{ gap: 8 }}>
|
|
469
|
+
<Text style={t.body}>{who === "Overseer" ? "The Overseer answered in its own chat, not here: it can't reply on a card." : `${who} answered in its chat.`}</Text>
|
|
470
|
+
{/* A 2.2.0-beta.3 ask of the Overseer: its answer is in the Overseer's chat (an-ask-goes-only-to-an-agent-that-can-answer-it). */}
|
|
471
|
+
<View style={{ flexDirection: "row" }}>{who === "Overseer"
|
|
472
|
+
? <Button theme={theme} compact={compact} icon="MessageSquare" title="Open Overseer" disabled={!request.askedOf || !openAgent} onPress={() => request.askedOf && openAgent?.(request.askedOf)} />
|
|
473
|
+
: <Button theme={theme} compact={compact} icon="MessageSquare" title="Open chat" onPress={openChat} />}</View>
|
|
474
|
+
</View>}
|
|
475
|
+
{request.state === "failed" && <Text style={t.body}>{request.error ?? "The ask didn't go through. Try again, or open the chat."}</Text>}
|
|
476
|
+
</View>;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function PermissionCard({ s, theme, compact, onDone }: { s: DeckCard["s"]; theme: Theme; compact: boolean; onDone: () => void }) {
|
|
480
|
+
const agent = useAgentLive(s.agentId);
|
|
481
|
+
const t = text(theme.colors, compact);
|
|
482
|
+
if (!agent.permissions.length) return <Text style={t.ask}>{s.line || "Permission"}</Text>;
|
|
483
|
+
return <View style={{ gap: 10 }}>{agent.permissions.map(p => <PermissionBlock key={p.id} p={p} theme={theme} compact={compact} busy={false} primary
|
|
484
|
+
onRespond={r => { void agent.handle?.respondToPermission({ requestId: p.id, response: r as never }); onDone(); }} />)}</View>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function BriefAsk({ s, theme, compact, deps }: { s: DeckCard["s"]; theme: Theme; compact: boolean; deps: CatchUpDeps }) {
|
|
488
|
+
const read = useRpc(inboxBriefRpc);
|
|
489
|
+
const brief = useQuery({ queryKey: ["follow-up", "home-brief", s.agentId, "catch-up"], queryFn: () => read({ agentId: s.agentId! }), enabled: !!s.agentId });
|
|
490
|
+
const b = liveBrief(brief.data?.brief);
|
|
491
|
+
if (!b) return <Text style={text(theme.colors, compact).ask}>{s.line}</Text>;
|
|
492
|
+
return <BriefCard {...({ embedded: true, item: { data: b }, theme, layout: { compact }, agentId: s.agentId, deps: deps.briefDeps } as unknown as Parameters<typeof BriefCard>[0])} />;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* More context: "I don't get it" first (most asks just need explaining), then the developer's own words, to one place:
|
|
497
|
+
* the card's workspace's main agent, the one that can answer on the card (an-ask-goes-only-to-an-agent-that-can-answer-
|
|
498
|
+
* it). It may wake, because the developer asked. The deck moves on and this workspace comes back when the answer is ready.
|
|
499
|
+
*/
|
|
500
|
+
function MorePanel({ theme, compact, onClose, onAsk }: { theme: Theme; compact: boolean; onClose: () => void; onAsk: (words: string) => Promise<void> }) {
|
|
501
|
+
const c = theme.colors; const t = text(c, compact);
|
|
502
|
+
const [words, setWords] = useState<string>(CONTEXT_ASKS[0].text);
|
|
503
|
+
const [picked, setPicked] = useState<string>(CONTEXT_ASKS[0].id);
|
|
504
|
+
const [busy, setBusy] = useState(false);
|
|
505
|
+
const [error, setError] = useState<string | null>(null);
|
|
506
|
+
const send = () => {
|
|
507
|
+
if (!words.trim() || busy) return;
|
|
508
|
+
setBusy(true); setError(null);
|
|
509
|
+
// The words stay unless the ask is recorded.
|
|
510
|
+
onAsk(words.trim()).catch(e => setError(errorText(e))).finally(() => setBusy(false));
|
|
511
|
+
};
|
|
512
|
+
return <View {...({ dataSet: { catchUpMore: "1" } } as object)} style={{ gap: 10 }}>
|
|
513
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
514
|
+
<Icon name="Sparkles" size={14} color={c.foreground} />
|
|
515
|
+
<Text style={[t.label, { flex: 1, fontWeight: "600" }]}>More context</Text>
|
|
516
|
+
<IconButton theme={theme} compact={compact} icon="X" label="Close more context" onPress={onClose} />
|
|
517
|
+
</View>
|
|
518
|
+
<View accessibilityRole="radiogroup" style={{ flexDirection: "row", flexWrap: "wrap", gap: 6 }}>
|
|
519
|
+
{CONTEXT_ASKS.map((x, i) => <Pressable key={x.id} accessibilityLabel={compact ? x.label : `${x.label} (${i + 1})`} accessibilityRole="radio" accessibilityState={{ checked: picked === x.id }} onPress={() => { setPicked(x.id); setWords(x.text); }}
|
|
520
|
+
style={{ minHeight: compact ? 36 : 28, justifyContent: "center", paddingHorizontal: 10, borderRadius: 999, borderWidth: 1, borderColor: picked === x.id ? c.foreground : c.border, backgroundColor: picked === x.id ? c.surface2 : "transparent" }}>
|
|
521
|
+
<Text style={[t.meta, { color: picked === x.id ? c.foreground : c.foregroundMuted }]}>{x.label}</Text>
|
|
522
|
+
</Pressable>)}
|
|
523
|
+
</View>
|
|
524
|
+
<View {...PRIMARY_FORM} style={{ gap: 10 }}>
|
|
525
|
+
<TextInput accessibilityLabel="What do you want to know?" placeholder="What do you want to know?" placeholderTextColor={c.foregroundMuted} value={words} multiline
|
|
526
|
+
onChangeText={v => { setWords(v); setPicked(CONTEXT_ASKS.find(x => x.text === v)?.id ?? ""); }}
|
|
527
|
+
style={{ minHeight: compact ? 84 : 56, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, backgroundColor: c.surface0 }} />
|
|
528
|
+
{!!error && <Text accessibilityRole="alert" style={[t.meta, { color: c.statusDanger }]}>{error}</Text>}
|
|
529
|
+
<View {...({ dataSet: { askAgent: "1" } } as object)} style={{ flexDirection: "row" }}>
|
|
530
|
+
<Button theme={theme} compact={compact} grow={compact} kind="primary" icon="MessageSquareText" title="Ask the agent" loading={busy} disabled={!words.trim() || busy}
|
|
531
|
+
accessibilityHint={compact ? "Asks this workspace's main agent, which may wake it" : `Asks this workspace's main agent, which may wake it. ${keyLabel("⌘↵", isMac())}`} onPress={send} />
|
|
532
|
+
</View>
|
|
533
|
+
</View>
|
|
534
|
+
<Text style={t.small}>This workspace steps aside while you keep going, and comes back as your next card with the answer. Back reaches it any time.</Text>
|
|
535
|
+
</View>;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function Finished({ theme, compact, stats, empty, onHome, onSkipped }: { theme: Theme; compact: boolean; stats: ReturnType<typeof statsOf>; empty: boolean; onHome: () => void; onSkipped: () => void }) {
|
|
539
|
+
const c = theme.colors; const t = text(c, compact);
|
|
540
|
+
// "All caught up" only when it is true: a skipped or waiting card means the developer is not, so the end says so.
|
|
541
|
+
const caughtUp = !stats.skipped && !stats.waiting;
|
|
542
|
+
const icon = caughtUp ? "Check" : stats.waiting ? "Hourglass" : "CornerUpRight";
|
|
543
|
+
const tone = caughtUp ? c.statusSuccess : stats.waiting ? c.statusWarning : c.foregroundMuted;
|
|
544
|
+
const line = [stats.done && `${stats.done} done`, stats.skipped && `${stats.skipped} skipped`, stats.later && `${stats.later} for later`, stats.gone && `${stats.gone} handled elsewhere`].filter(Boolean).join(" · ");
|
|
545
|
+
return <ScrollView contentContainerStyle={{ flexGrow: 1, justifyContent: "center", alignItems: "center", padding: 24, gap: 14 }}>
|
|
546
|
+
<View style={{ width: 56, height: 56, borderRadius: 28, alignItems: "center", justifyContent: "center", backgroundColor: tint(tone, c) }}>
|
|
547
|
+
<Icon name={icon} size={28} color={tone} />
|
|
548
|
+
</View>
|
|
549
|
+
<Text accessibilityRole="header" style={t.headline}>{empty ? MODE.empty : caughtUp ? MODE.finished : MODE.endOfDeck}</Text>
|
|
550
|
+
{!!line && <Text style={[t.body, { color: c.foregroundMuted, textAlign: "center" }]}>{line}</Text>}
|
|
551
|
+
{stats.waiting > 0 && <Text style={[t.body, { textAlign: "center" }]}>{`${MODE.waiting(stats.waiting)}. ${stats.waiting === 1 ? "It comes" : "They come"} back here when the answer is ready; Back reaches ${stats.waiting === 1 ? "it" : "them"} now.`}</Text>}
|
|
552
|
+
{stats.done > 0 && <Text style={[t.meta, { textAlign: "center", maxWidth: 420 }]}>Your answers are on their way; agents pick them up as soon as they're free. Anything new shows in Needs you and the pill.</Text>}
|
|
553
|
+
<View style={{ flexDirection: compact ? "column" : "row", alignSelf: compact ? "stretch" : "center", gap: 8, marginTop: 6 }}>
|
|
554
|
+
{stats.skipped > 0 && <Button theme={theme} compact={compact} grow={compact} kind="primary" icon="CornerUpRight" title={`Catch up on ${stats.skipped} skipped`} onPress={onSkipped} />}
|
|
555
|
+
<Button theme={theme} compact={compact} grow={compact} kind={stats.skipped ? "secondary" : "primary"} icon="House" title="Back to Home" onPress={onHome} />
|
|
556
|
+
</View>
|
|
557
|
+
</ScrollView>;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/** S: the keys, from the one list the handler reads (shared/catch-up.ts). A dialog over the card; S or its X closes it. */
|
|
561
|
+
export function KeysSheet({ theme, onClose }: { theme: Theme; onClose: () => void }) {
|
|
562
|
+
const c = theme.colors; const t = text(c, false);
|
|
563
|
+
const row = (k: typeof CATCH_UP_KEYS[number]) => <View key={`${k.action}-${k.key}`} style={{ flexDirection: "row", gap: 10, alignItems: "center" }}>
|
|
564
|
+
<View style={{ minWidth: 64 }}><Text style={[t.meta, { alignSelf: "flex-start", paddingHorizontal: 6, borderRadius: 4, borderWidth: 1, borderColor: c.border, color: c.foreground, fontVariant: ["tabular-nums"] }]}>{keyLabel(k.key, isMac())}</Text></View>
|
|
565
|
+
<Text style={t.meta}>{k.what}</Text>
|
|
566
|
+
</View>;
|
|
567
|
+
const section = (title: string, keys: readonly typeof CATCH_UP_KEYS[number][]) => <View style={{ gap: 6 }}>
|
|
568
|
+
<Text style={[t.small, { fontWeight: "600" }]}>{title}</Text>{keys.map(row)}
|
|
569
|
+
</View>;
|
|
570
|
+
return <View accessibilityRole={"dialog" as never} accessibilityLabel="Catch up keys" style={{ position: "absolute", zIndex: 10, right: 20, top: 8, width: 300, padding: 16, gap: 12, borderRadius: 10, borderWidth: 1, borderColor: c.border, backgroundColor: c.surface1, shadowColor: "#000", shadowOpacity: 0.25, shadowRadius: 12 }}>
|
|
571
|
+
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
|
572
|
+
<Text style={[t.label, { flex: 1, fontWeight: "600" }]}>Keys</Text>
|
|
573
|
+
<IconButton theme={theme} compact={false} icon="X" label="Close the keys (S)" tooltip onPress={onClose} />
|
|
574
|
+
</View>
|
|
575
|
+
{section("On a card", CATCH_UP_KEYS.filter(k => !k.when))}
|
|
576
|
+
{section("In More context", CATCH_UP_KEYS.filter(k => k.when === "more"))}
|
|
577
|
+
{section("In the queue", CATCH_UP_KEYS.filter(k => k.when === "rail"))}
|
|
578
|
+
</View>;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** A desktop hover title on any control (react-native-web drops `title` on a Pressable; IconButton does the same). */
|
|
582
|
+
function Tip({ label, children }: { label: string; children: ReactNode }) {
|
|
583
|
+
const ref = useRef<View>(null);
|
|
584
|
+
useEffect(() => { if (Platform.OS === "web") (ref.current as unknown as { setAttribute?: (k: string, v: string) => void } | null)?.setAttribute?.("title", label); }, [label]);
|
|
585
|
+
return Platform.OS === "web" ? <View ref={ref}>{children}</View> : <>{children}</>;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Home's way in. It counts cards (one per thing to act on), which can differ from Needs you's workspace count beside
|
|
590
|
+
* it, so its accessible name and desktop tooltip say what the number is.
|
|
591
|
+
*/
|
|
592
|
+
export function CatchUpButton({ theme, compact, count, onPress }: { theme: Theme; compact: boolean; count: number; onPress: () => void }): ReactNode {
|
|
593
|
+
if (!count) return null;
|
|
594
|
+
const label = MODE.buttonLabel(count);
|
|
595
|
+
const button = <Button theme={theme} compact={compact} grow={compact} kind="primary" icon="Layers" title={MODE.button(count)} accessibilityLabel={label} onPress={onPress} />;
|
|
596
|
+
return Platform.OS === "web" && !compact ? <View {...({ dataSet: { tooltip: label }, title: label } as object)}>{button}</View> : button;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/** Tell the agent something with or without acting: a plain message, the detail pane's reply box in a line. */
|
|
600
|
+
function NoteRow({ theme, compact, agentId }: { theme: Theme; compact: boolean; agentId: string }) {
|
|
601
|
+
const c = theme.colors;
|
|
602
|
+
const agent = useAgentLive(agentId);
|
|
603
|
+
const [words, setWords] = useState("");
|
|
604
|
+
return <View {...PRIMARY_FORM} style={{ flexDirection: "row", alignItems: "flex-end", gap: 8 }}>
|
|
605
|
+
<TextInput accessibilityLabel="Tell the agent something" placeholder="Tell the agent something" placeholderTextColor={c.foregroundMuted} value={words} onChangeText={setWords} multiline
|
|
606
|
+
style={{ flex: 1, minHeight: compact ? 44 : 36, paddingHorizontal: 10, paddingVertical: 8, borderRadius: 6, borderWidth: 1, borderColor: c.border, color: c.foreground, backgroundColor: c.surface0 }} />
|
|
607
|
+
<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(""); }} />
|
|
608
|
+
</View>;
|
|
609
|
+
}
|