@andrioid/paseo-attention-span 0.1.2 β†’ 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,19 +4,21 @@ import { Markdown, Modal, TextInput, useToast } from "@getpaseo/plugin/client/ui
4
4
  import { useQuery, useQueryClient } from "@tanstack/react-query";
5
5
  import { type ReactNode, useState } from "react";
6
6
  import { Pressable, ScrollView, Text, View } from "react-native";
7
- import { type ActionId, type AgentSummary, type Chip, type FailingChecks, type Item, type NextUpIssue, type Section, type SectionId, type SubRow, TAB_FEED, type TabId, type Target } from "../shared/attention";
8
- import type { AttentionConfig, SessionKind } from "../shared/config";
9
- import { ago, linkList } from "../shared/format";
7
+ import { type ActionId, type AgentSummary, type AttentionView, type Chip, type FailingChecks, type Item, itemSessions, type NextUpIssue, type Section, type SectionId, type SubRow, TAB_FEED, type TabId, type Target } from "../shared/attention";
8
+ import { type AttentionConfig, nextUpSources, type SessionKind } from "../shared/config";
9
+ import { ago, linkList, repoLabel } from "../shared/format";
10
10
  import { ACTION_SESSION, renderPrompt } from "../shared/prompts";
11
11
  import * as rpc from "../shared/rpc";
12
12
  import { blocks } from "../shared/setup";
13
13
  import { useAttention } from "./data";
14
+ import { CardList, CardRow, type CardProps } from "./card";
14
15
  import type { IconName } from "./icons";
15
16
  import { NextUpList } from "./next-up";
16
- import { ActionSheet, DetailLines, type SheetEntry } from "./sheet";
17
+ import { agentSignal, openSessionEntry, sessionsGroup } from "./session-menu";
18
+ import { ActionSheet, DetailLines, type MenuGroup, MenuSheet, type SheetEntry } from "./sheet";
17
19
  import { branchWorkspaces, findCheckout, githubProjects, itemAgents, listProfiles, noProjectMessage, resolveAgentConfig, startSession } from "./sessions";
18
20
  import { SetupChecklist } from "./setup";
19
- import { Avatar, Button, KeepStyles, Meta, SectionHeader, StylesProvider, TablerIcon, Toggle, useCopy, useHover, useStyles } from "./ui";
21
+ import { type Anchor, Avatar, Button, KeepStyles, Loading, Meta, SectionHeader, SpinningIcon, StylesProvider, TablerIcon, Toggle, useCopy, useHover, useStyles } from "./ui";
20
22
 
21
23
  // The agent icon marks every action that starts an agent session; the rest act on GitHub right away [ATT-13].
22
24
  const ACTION_ICONS: Record<ActionId, IconName> = {
@@ -66,7 +68,7 @@ function actionDetail(action: Exclude<ActionId, "rerun">, item: Item): string {
66
68
  return {
67
69
  reply: item.person ? `Opens ${item.person.login}'s comment on GitHub` : "Opens it on GitHub",
68
70
  acknowledge:
69
- comments.length === 1 ? `Reacts πŸ‘ to ${comments[0].author}'s comment, which clears it` : `Pick which of the ${comments.length} waiting comments get a πŸ‘`,
71
+ comments.length === 1 ? `Reacts to ${comments[0].author}'s comment, which clears it` : `Pick which of the ${comments.length} waiting comments to react to`,
70
72
  review: "An agent reviews the PR in a checkout and reports back. Nothing is posted",
71
73
  fix: "An agent reads the failing logs and commits a fix, without pushing",
72
74
  address: "An agent works through the unresolved comments and applies the trivial ones, without pushing",
@@ -94,16 +96,6 @@ function rerunEntry(failing: FailingChecks[] | undefined, loading: boolean): { d
94
96
  return { detail: `${names} Β· ${reruns ? `rerun ${reruns === 1 ? "once" : `${reruns} times`} already` : "not rerun yet"}`, runIds: runs.map((run) => run.id) };
95
97
  }
96
98
 
97
- // "Continue review" keeps what the session is for [SES-03].
98
- const CONTINUE_LABELS: Record<SessionKind, string> = {
99
- review: "Continue review",
100
- fix: "Continue fix",
101
- address: "Continue comments",
102
- rebase: "Continue rebase",
103
- refresh: "Continue refresh",
104
- start: "Continue",
105
- };
106
-
107
99
  const SECTION_ICONS: Record<SectionId, IconName> = {
108
100
  reply: "reply",
109
101
  review: "review",
@@ -142,6 +134,16 @@ interface Placing {
142
134
  before?: () => Promise<unknown>;
143
135
  }
144
136
 
137
+ // Session options, before it starts [SES-02].
138
+ export interface OptionsSpec {
139
+ itemKey: string;
140
+ title: string;
141
+ kind: SessionKind;
142
+ target: Target;
143
+ // Claims an issue first [NXT-05].
144
+ before?: () => Promise<unknown>;
145
+ }
146
+
145
147
  // Something I just did, offered for undo until the tab changes [ATT-08, ATT-14].
146
148
  interface Undoable {
147
149
  id: number;
@@ -150,14 +152,6 @@ interface Undoable {
150
152
  undo: () => Promise<unknown>;
151
153
  }
152
154
 
153
- // A session started from the item, as a signal [ATT-07].
154
- function agentSignal(agent: AgentSummary): Chip {
155
- if (agent.requiresAttention) return { text: "agent needs you", tone: "warn" };
156
- if (agent.status === "running" || agent.status === "initializing") return { text: "agent working", tone: "good" };
157
- if (agent.status === "error") return { text: "agent failed", tone: "bad" };
158
- return { text: "agent idle", tone: "neutral" };
159
- }
160
-
161
155
  // `openSettings` opens the orgs and repos settings [SRC-02].
162
156
  export function AttentionScreen({ theme, layout, navigation, openSettings }: PluginScreenProps & { openSettings?: () => void }) {
163
157
  return (
@@ -179,6 +173,9 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
179
173
  const undismiss = useRpc(rpc.undismissItem);
180
174
  const restore = useRpc(rpc.restoreDismissed);
181
175
  const saveScopes = useRpc(rpc.setScopes);
176
+ const saveSources = useRpc(rpc.setSources);
177
+ const closeIssue = useRpc(rpc.closeIssue);
178
+ const reopenIssue = useRpc(rpc.reopenIssue);
182
179
  const update = useRpc(rpc.updateBranch);
183
180
  const merge = useRpc(rpc.mergePullRequest);
184
181
  const close = useRpc(rpc.closePullRequest);
@@ -193,9 +190,11 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
193
190
  const fetchDefaultBranch = useRpc(rpc.defaultBranch);
194
191
  const defaultBranch: DefaultBranch = async (repo) => (await fetchDefaultBranch({ repo })).name;
195
192
  const [tab, setTab] = useState<TabId>("doing");
196
- const [busy, setBusy] = useState<string | null>(null);
193
+ // Every card with a change still running: each runs on its own.
194
+ const [busy, setBusy] = useState<ReadonlySet<string>>(new Set());
197
195
  const [undoable, setUndoable] = useState<Undoable[]>([]);
198
196
  const [placing, setPlacing] = useState<Placing | null>(null);
197
+ const [options, setOptions] = useState<OptionsSpec | null>(null);
199
198
  const view = attention.data;
200
199
  // Only when something fails: is it setup, and what's missing [SET-01]?
201
200
  const fetchSetup = useRpc(rpc.setupStatus);
@@ -204,27 +203,24 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
204
203
  const [checking, setChecking] = useState(false);
205
204
 
206
205
  async function run(key: string, label: string, work: () => Promise<unknown>) {
207
- setBusy(key);
206
+ setBusy((keys) => new Set(keys).add(key));
208
207
  try {
209
208
  await work();
210
209
  } catch (error) {
211
210
  toast.error(`${label} failed: ${(error as Error).message}`);
212
211
  } finally {
213
- setBusy(null);
212
+ setBusy((keys) => new Set([...keys].filter((other) => other !== key)));
214
213
  }
215
214
  }
216
215
 
217
- function offerUndo(text: string, undo: () => Promise<unknown>, dismissal?: boolean) {
218
- setUndoable((rows) => [...rows, { id: Date.now() + Math.random(), text, undo, dismissal }]);
219
- }
220
-
221
- // A change on GitHub from one tap, without confirming: Undo instead, where GitHub can take it back [SAFE-01, ATT-14].
222
- function onGitHub(key: string, label: string, work: () => Promise<unknown>, done: string, undo?: () => Promise<unknown>) {
216
+ // A change from one tap, without confirming: Undo instead, where it can be taken back [SAFE-01, ATT-08, ATT-14].
217
+ // The server answers each with the list after it, so nothing needs a refresh.
218
+ function change(key: string, label: string, work: () => Promise<AttentionView>, done: string, undo?: () => Promise<AttentionView>, dismissal?: boolean) {
223
219
  void run(key, label, async () => {
224
- await work();
225
- if (undo) offerUndo(done, undo);
226
- else toast.show(done, { variant: "success" });
227
- void attention.refreshNow("live").catch(() => {}); // the server is already refreshing; this waits for it
220
+ attention.setView(await work());
221
+ if (!undo) return toast.show(done, { variant: "success" });
222
+ const id = Date.now() + Math.random();
223
+ setUndoable((rows) => [...rows, { id, text: done, undo: async () => attention.setView(await undo()), dismissal }]);
228
224
  });
229
225
  }
230
226
 
@@ -238,10 +234,8 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
238
234
  openAgent(agentId);
239
235
  }
240
236
 
241
- // One tap: continue the item's session, or start one with defaults [SES-01, SES-03].
237
+ // One tap: start a session with defaults [SES-01]. An open one is offered first, by the card [SES-03].
242
238
  async function startWithDefaults(itemKey: string, kind: SessionKind, target: Target, before?: () => Promise<unknown>) {
243
- const existing = (view?.fixtureAgents ?? agents.data)?.[itemKey];
244
- if (existing) return openAgent(existing.id);
245
239
  if (!view) return;
246
240
  await run(itemKey, "Starting the session", () => startNow(itemKey, kind, target, view.config, before));
247
241
  }
@@ -284,13 +278,14 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
284
278
  if (!view) {
285
279
  return (
286
280
  <View style={[styles.screen, styles.content]}>
287
- <Text style={attention.error ? styles.danger : styles.muted}>{attention.error ? `Couldn't load Attention Span: ${(attention.error as Error).message}` : "Loading…"}</Text>
281
+ {attention.error ? <Text style={styles.danger}>Couldn't load Attention Span: {(attention.error as Error).message}</Text> : <Loading text="Loading…" />}
288
282
  </View>
289
283
  );
290
284
  }
291
285
 
292
286
  // Each tab shows how fresh its own feed is.
293
287
  const feed = view.feeds[TAB_FEED[tab]];
288
+ const refreshing = feed.refreshing || attention.isFetching;
294
289
  const tooLong = view.doing.find((section) => section.id === "too_long")?.items.length ?? 0;
295
290
  const counts: Record<TabId, number> = {
296
291
  history: view.history.filter((item) => item.section === "done").length,
@@ -298,14 +293,13 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
298
293
  waiting: view.waiting.reduce((sum, section) => sum + section.items.length, 0),
299
294
  next: view.assigned.length + view.unclaimed.length,
300
295
  };
301
- // The repo is worth showing only when the list spans several.
302
- const repos = new Set([...view.doing, ...view.waiting].flatMap((section) => section.items.map((item) => item.repo)));
303
296
 
304
297
  const actions: Actions = {
305
- agents: view.fixtureAgents ?? agents.data ?? {},
298
+ agents: view.fixtureAgents ?? agents.data ?? [],
299
+ startWithOptions: setOptions,
306
300
  busy,
307
301
  config: view.config,
308
- showRepo: repos.size > 1,
302
+ login: view.login,
309
303
  fetchContext,
310
304
  fetchDetails,
311
305
  defaultBranch,
@@ -316,38 +310,26 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
316
310
  const { target } = item;
317
311
  if (action === "reply") return void openExternalUrl(item.person?.url ?? item.url);
318
312
  if (session) return void startWithDefaults(item.key, session, target);
319
- if (action === "update")
320
- void run(item.key, "Update", async () => {
321
- await update({ target });
322
- toast.show(`Updating PR ${target.number} with ${target.baseRefName}`, { variant: "success" });
323
- });
313
+ if (action === "update") change(item.key, "Update", () => update({ key: item.key, target }), `Updating PR ${target.number} with ${target.baseRefName}`);
324
314
  // [PRS-11]
325
315
  if (action === "ready")
326
- onGitHub(item.key, "Ready for review", () => setReady({ target, ready: true }), `PR ${target.number} is ready for review`, () => setReady({ target, ready: false }));
316
+ change(item.key, "Ready for review", () => setReady({ key: item.key, target, ready: true }), `PR ${target.number} is ready for review`, () => setReady({ key: item.key, target, ready: false }));
327
317
  // [PRS-10]
328
318
  if (action === "automerge")
329
- onGitHub(item.key, "Auto-merge", () => setAutoMerge({ target, on: true }), `PR ${target.number} merges once checks pass`, () => setAutoMerge({ target, on: false }));
319
+ change(item.key, "Auto-merge", () => setAutoMerge({ key: item.key, target, on: true }), `PR ${target.number} merges once checks pass`, () => setAutoMerge({ key: item.key, target, on: false }));
330
320
  },
331
321
  // [PRS-09]
332
- rerun: (item, runIds) =>
333
- onGitHub(item.key, "Rerun", () => rerunFailed({ repo: item.target.repo, runIds }), `Rerunning the failed jobs of PR ${item.target.number}`),
322
+ rerun: (item, runIds) => change(item.key, "Rerun", () => rerunFailed({ key: item.key, repo: item.target.repo, runIds }), `Rerunning the failed jobs of PR ${item.target.number}`),
334
323
  // [MEN-07]
335
324
  acknowledge: (item, ids) =>
336
- onGitHub(item.key, "πŸ‘", () => react({ subjectIds: ids, on: true }), `Reacted πŸ‘ to ${ids.length === 1 ? "a comment" : `${ids.length} comments`} on #${item.number}`, () =>
337
- react({ subjectIds: ids, on: false }),
325
+ change(item.key, "Acknowledge", () => react({ key: item.key, subjectIds: ids, on: true }), `Acknowledged ${ids.length === 1 ? "a comment" : `${ids.length} comments`} on #${item.number}`, () =>
326
+ react({ key: item.key, subjectIds: ids, on: false }),
338
327
  ),
339
328
  confirm: (item, action, comment) =>
340
- void run(item.key, action === "merge" ? "Merge" : "Close", async () => {
341
- if (action === "merge") await merge({ target: item.target });
342
- else await close({ target: item.target, comment });
343
- toast.show(`PR ${item.target.number} ${action === "merge" ? "merged" : "closed"}`, { variant: "success" });
344
- await attention.refreshNow("live");
345
- }),
346
- dismiss: (item) =>
347
- void run(item.key, "Dismiss", async () => {
348
- attention.setView(await dismiss({ key: item.key }));
349
- offerUndo(`Dismissed β€œ${item.title}”`, async () => attention.setView(await undismiss({ key: item.key })), true);
350
- }),
329
+ action === "merge"
330
+ ? change(item.key, "Merge", () => merge({ key: item.key, target: item.target }), `PR ${item.target.number} merged`)
331
+ : change(item.key, "Close", () => close({ key: item.key, target: item.target, comment }), `PR ${item.target.number} closed`),
332
+ dismiss: (item) => change(item.key, "Dismiss", () => dismiss({ key: item.key }), `Dismissed β€œ${item.title}”`, () => undismiss({ key: item.key }), true),
351
333
  };
352
334
 
353
335
  const switchTab = (id: TabId) => {
@@ -364,9 +346,15 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
364
346
  ))}
365
347
  </View>
366
348
  <View style={[styles.row, { gap: 16 }]}>
367
- <Pressable accessibilityRole="button" accessibilityLabel="Refresh now" style={styles.row} onPress={() => void attention.refreshNow(TAB_FEED[tab]).catch(() => {})}>
368
- <TablerIcon name="update" size={14} />
369
- <Text style={styles.muted}>{feed.refreshing || attention.isFetching ? "refreshing…" : feed.fetchedAt ? `${ago(feed.fetchedAt)} ago` : "never"}</Text>
349
+ <Pressable
350
+ accessibilityRole="button"
351
+ accessibilityLabel="Refresh now"
352
+ accessibilityState={{ busy: refreshing }}
353
+ style={styles.row}
354
+ onPress={() => void attention.refreshNow(TAB_FEED[tab]).catch(() => {})}
355
+ >
356
+ <SpinningIcon name="update" size={14} spinning={refreshing} />
357
+ <Text style={styles.muted}>{feed.fetchedAt ? `${ago(feed.fetchedAt)} ago` : "never"}</Text>
370
358
  </Pressable>
371
359
  {openSettings ? (
372
360
  <Pressable accessibilityRole="button" accessibilityLabel="Attention Span settings" onPress={openSettings} hitSlop={8}>
@@ -389,7 +377,6 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
389
377
  void run(String(row.id), "Undo", async () => {
390
378
  await row.undo();
391
379
  setUndoable((rows) => rows.filter((other) => other.id !== row.id));
392
- if (!row.dismissal) void attention.refreshNow("live").catch(() => {});
393
380
  })
394
381
  }
395
382
  />
@@ -426,22 +413,40 @@ function AttentionList({ navigation, openSettings }: Pick<PluginScreenProps, "na
426
413
  attention.setView({ ...view, scopes });
427
414
  saveScopes({ scopes }).catch((error) => toast.error(`Saving the filter failed: ${(error as Error).message}`));
428
415
  }}
416
+ sources={nextUpSources(view.config)}
417
+ selectedSources={view.sources}
418
+ onSelectSources={(sources) => {
419
+ attention.setView({ ...view, sources });
420
+ saveSources({ sources }).catch((error) => toast.error(`Saving the filter failed: ${(error as Error).message}`));
421
+ }}
429
422
  agents={actions.agents}
423
+ login={view.login}
430
424
  busy={busy}
431
425
  fetchDetails={fetchDetails}
432
426
  onOpenAgent={openAgent}
433
427
  onStart={(issue, claimFirst) => {
434
428
  const target = issueTarget(issue);
435
- void startWithDefaults(issue.key, "start", target, claimFirst ? () => claim({ target }) : undefined);
429
+ void startWithDefaults(issue.key, "start", target, claimFirst ? async () => attention.setView(await claim({ key: issue.key, target })) : undefined);
430
+ }}
431
+ onOptions={(issue, claimFirst, label) => {
432
+ const target = issueTarget(issue);
433
+ setOptions({ itemKey: issue.key, title: `${label}: ${issue.title}`, kind: "start", target, before: claimFirst ? async () => attention.setView(await claim({ key: issue.key, target })) : undefined });
436
434
  }}
437
435
  // Claim without starting, or give it back; each undoes the other [NXT-07].
438
436
  onClaim={(issue, on) => {
439
437
  const target = issueTarget(issue);
440
- const [take, giveBack] = [() => claim({ target }), () => unclaim({ target })];
441
- onGitHub(issue.key, on ? "Claim" : "Unclaim", on ? take : giveBack, `${on ? "Claimed" : "Unclaimed"} #${issue.number}`, on ? giveBack : take);
438
+ const [take, giveBack] = [() => claim({ key: issue.key, target }), () => unclaim({ key: issue.key, target })];
439
+ change(issue.key, on ? "Claim" : "Unclaim", on ? take : giveBack, `${on ? "Claimed" : "Unclaimed"} #${issue.number}`, on ? giveBack : take);
440
+ }}
441
+ // Undo reopens; a comment already posted stays [NXT-11].
442
+ onCloseIssue={(issue, reason, comment) => {
443
+ const target = issueTarget(issue);
444
+ const done = `Closed #${issue.number} as ${reason === "completed" ? "completed" : "not planned"}`;
445
+ change(issue.key, "Close", () => closeIssue({ key: issue.key, target, reason, comment: comment || undefined }), done, () => reopenIssue({ key: issue.key, target }));
442
446
  }}
443
447
  />
444
448
  ) : null}
449
+ {options ? <SessionOptions spec={options} actions={actions} onClose={() => setOptions(null)} /> : null}
445
450
  {placing ? <CodeRepoPicker issueRepo={placing.target.repo} missing={placing.missing} onPick={place} onClose={() => setPlacing(null)} /> : null}
446
451
  </ScrollView>
447
452
  );
@@ -467,10 +472,11 @@ function Tab({ icon, label, count, active, onPress }: { icon: IconName; label: s
467
472
  }
468
473
 
469
474
  interface Actions {
470
- agents: Record<string, AgentSummary>;
471
- busy: string | null;
475
+ agents: AgentSummary[];
476
+ startWithOptions: (spec: OptionsSpec) => void;
477
+ busy: ReadonlySet<string>;
472
478
  config: AttentionConfig;
473
- showRepo: boolean;
479
+ login: string | null;
474
480
  fetchContext: FetchContext;
475
481
  fetchDetails: FetchDetails;
476
482
  defaultBranch: DefaultBranch;
@@ -483,31 +489,32 @@ interface Actions {
483
489
  started: (agentId: string) => Promise<void>;
484
490
  }
485
491
 
486
- function stateIcon(item: Item, c: ReturnType<typeof useStyles>["c"]): { name: IconName; color: string } {
487
- if (item.closedAt) return item.kind === "pr" ? { name: "merge", color: c.accent } : { name: "issueClosed", color: item.chips.length ? c.foregroundMuted : c.accent };
488
- if (item.kind === "issue") return { name: "issue", color: c.statusSuccess };
489
- return item.draft ? { name: "draft", color: c.foregroundMuted } : { name: "pr", color: c.statusSuccess };
492
+ // What the card is: open, draft, merged or closed. Urgency stays in the chips and section headers.
493
+ function stateMark(item: Item): CardProps["mark"] {
494
+ if (item.closedAt) return item.kind === "pr" ? { icon: "merge", tone: "good" } : { icon: "issueClosed", tone: item.chips.length ? "neutral" : "good" };
495
+ if (item.kind === "issue") return { icon: "issue", tone: "good" };
496
+ return item.draft ? { icon: "draft", tone: "neutral" } : { icon: "pr", tone: "good" };
490
497
  }
491
498
 
492
499
  // A card that works collapsed: its main action and β‹―. Tapping it opens the sheet with everything else [ATT-05, ATT-06].
493
500
  const isRed = (chips: Chip[]) => chips.some((chip) => chip.tone === "bad");
494
501
 
495
- type Sheet = "item" | "acknowledge" | { options: SessionKind } | null;
502
+ // The sheet, Acknowledge, or a split button's menu: for the open sessions, or for starting one of `kind`.
503
+ type Sheet = "item" | "acknowledge" | { anchor?: Anchor; kind?: SessionKind } | null;
504
+
505
+ // A session on an item that has no session action of its own starts with this prompt; it's editable first.
506
+ const fallbackKind = (item: Item): SessionKind => (item.target.kind === "issue" ? "start" : "review");
496
507
 
497
508
  function ItemRow({ item, first, actions }: { item: Item; first: boolean; actions: Actions }) {
498
- const styles = useStyles();
499
- const agent = actions.agents[item.key];
500
- const chips = agent ? [...item.chips, agentSignal(agent)] : item.chips;
509
+ // An open session leads; without one, the item's own action does [SES-03].
510
+ const sessions = itemSessions(actions.agents, item);
511
+ const chips = sessions[0] ? [...item.chips, agentSignal(sessions[0])] : item.chips;
501
512
  const [sheet, setSheet] = useState<Sheet>(null);
502
513
  const [confirm, setConfirm] = useState<"merge" | "close" | null>(null);
503
- const [comment, setComment] = useState("");
504
- const sessionAction = item.actions.find((action) => ACTION_SESSION[action]);
505
- const sessionKind = sessionAction ? ACTION_SESSION[sessionAction] : undefined;
506
514
  const main = item.actions[0];
507
- const facts = [`#${item.number}`, ...(actions.showRepo ? [item.repo.split("/")[1]] : [])];
515
+ const mainKind = main ? ACTION_SESSION[main] : undefined;
508
516
  // The full stack is in the sheet; the card shows the PRs that need attention [ATT-04].
509
517
  const children = item.children.filter((child) => child.attention || isRed(child.chips));
510
- const icon = stateIcon(item, styles.c);
511
518
  const open = () => setSheet("item");
512
519
  const copy = useCopy();
513
520
  const history = item.section === "done" || item.section === "reviewed";
@@ -518,82 +525,122 @@ function ItemRow({ item, first, actions }: { item: Item; first: boolean; actions
518
525
  else if (action === "acknowledge") setSheet("acknowledge");
519
526
  else actions.act(item, action);
520
527
  }
521
- const handlers: SheetHandlers = { onPerform: perform, onOptions: (kind) => setSheet({ options: kind }), onClose: () => setSheet(null) };
528
+ const onMenu = (kind?: SessionKind) => (anchor: Anchor | undefined) => setSheet({ anchor, kind });
529
+ const handlers: SheetHandlers = { onPerform: perform, onMenu, onClose: () => setSheet(null) };
522
530
  // A menu with one action is a wasted tap: show that action instead of β‹―. The card still opens the sheet [ATT-06].
523
- const entries = sheetEntries(item, agent, actions, handlers);
531
+ const entries = sheetEntries(item, sessions, actions, handlers);
524
532
  const only = entries.length === 1 ? entries[0] : undefined;
525
-
526
- const buttons = (
527
- <View style={styles.wrap}>
528
- {actions.busy === item.key ? (
529
- <Text style={styles.muted}>working…</Text>
530
- ) : agent && sessionKind ? (
531
- <Button label={CONTINUE_LABELS[sessionKind]} icon="agent" variant="calm" onPress={() => actions.openAgent(agent.id)} />
532
- ) : main ? (
533
- <Button label={actionLabel(main, item)} icon={ACTION_ICONS[main]} variant="calm" onPress={() => perform(main)} />
534
- ) : null}
535
- {only ? (
536
- <Button icon={only.icon} variant="ghost" accessibilityLabel={only.label} onPress={only.onPress} />
537
- ) : (
538
- <Button icon="dots" variant="ghost" accessibilityLabel="More actions" onPress={open} />
539
- )}
540
- {/* History is where I report from, so its cards copy their link in one tap [ATT-15]. */}
541
- {history ? <Button icon="copy" variant="ghost" accessibilityLabel={`Copy link to #${item.number}`} onPress={() => copy(item.url, `Copied link to #${item.number}`)} /> : null}
542
- </View>
543
- );
533
+ const confirmed = (action: "merge" | "close") => (comment: string) => (setConfirm(null), actions.confirm(item, action, comment));
534
+ const sessionMenu = { label: "Session choices", onPress: onMenu() };
544
535
 
545
536
  return (
546
- <View style={first ? null : styles.divider}>
547
- <View style={styles.item}>
548
- <View style={{ paddingTop: 3 }}>
549
- <TablerIcon name={icon.name} color={icon.color} size={18} />
550
- </View>
551
- <View style={styles.body}>
552
- <Pressable accessibilityRole="button" accessibilityLabel={`${item.title}, more`} onPress={open} style={{ gap: 6 }}>
553
- <Text style={styles.title} numberOfLines={styles.compact ? 2 : 1}>
554
- {item.title}
555
- </Text>
556
- <Meta facts={facts} chips={chips} />
537
+ <CardRow
538
+ first={first}
539
+ mark={stateMark(item)}
540
+ title={item.title}
541
+ meta={{
542
+ place: `${repoLabel(item.repo, actions.login)} #${item.number}`,
543
+ when: item.closedAt ? `${item.kind === "pr" ? "merged" : "closed"} ${ago(item.closedAt)} ago` : undefined,
544
+ signals: chips,
545
+ }}
546
+ extra={
547
+ item.person || children.length > 0 ? (
548
+ <>
557
549
  {item.person ? <PersonQuote person={item.person} expanded={false} /> : null}
558
550
  {children.length > 0 ? <StackLine rows={children} merged={!!item.closedAt} /> : null}
559
- </Pressable>
560
- {styles.compact ? buttons : null}
561
- {confirm ? (
562
- <View style={styles.panel}>
563
- <Text style={styles.text}>
564
- {confirm === "merge"
565
- ? `Merge PR ${item.target.number} into ${item.target.baseRefName} (${item.target.mergeMethod})?`
566
- : `Close PR ${item.target.number}? A comment is only posted if you write one.`}
567
- </Text>
568
- {confirm === "close" ? (
569
- <TextInput style={styles.input} placeholder="Closing comment (optional)" placeholderTextColor={styles.c.foregroundMuted} value={comment} onChangeText={setComment} multiline />
570
- ) : null}
571
- <View style={styles.wrap}>
572
- <Button label={confirm === "merge" ? "Merge" : "Close PR"} icon={confirm} variant="solid" onPress={() => (setConfirm(null), actions.confirm(item, confirm, comment))} />
573
- <Button label="Cancel" onPress={() => setConfirm(null)} />
574
- </View>
575
- </View>
551
+ </>
552
+ ) : null
553
+ }
554
+ onOpen={open}
555
+ busy={actions.busy.has(item.key)}
556
+ primary={
557
+ sessions[0]
558
+ ? { label: "Open session", icon: "agent", onPress: () => actions.openAgent(sessions[0].id), menu: sessionMenu }
559
+ : main
560
+ ? {
561
+ label: actionLabel(main, item),
562
+ icon: ACTION_ICONS[main],
563
+ onPress: () => perform(main),
564
+ menu: mainKind ? { label: `${actionLabel(main, item)} choices`, onPress: onMenu(mainKind) } : undefined,
565
+ }
566
+ : undefined
567
+ }
568
+ secondary={[
569
+ only ? { label: only.label, icon: only.icon, onPress: only.onPress } : { label: "More actions", icon: "dots", onPress: open },
570
+ // History is where I report from, so its cards copy their link in one tap [ATT-15].
571
+ ...(history ? [{ label: `Copy link to #${item.number}`, icon: "copy" as const, onPress: () => copy(item.url, `Copied link to #${item.number}`) }] : []),
572
+ ]}
573
+ confirm={
574
+ confirm === "merge"
575
+ ? {
576
+ text: `Merge PR ${item.target.number} into ${item.target.baseRefName} (${item.target.mergeMethod})?`,
577
+ choices: [{ label: "Merge", icon: "merge", solid: true, onConfirm: confirmed("merge") }],
578
+ onCancel: () => setConfirm(null),
579
+ }
580
+ : confirm === "close"
581
+ ? {
582
+ text: `Close PR ${item.target.number}? A comment is only posted if you write one.`,
583
+ comment: true,
584
+ choices: [{ label: "Close PR", icon: "close", solid: true, onConfirm: confirmed("close") }],
585
+ onCancel: () => setConfirm(null),
586
+ }
587
+ : null
588
+ }
589
+ overlay={
590
+ <>
591
+ {sheet === "item" ? <ItemSheet item={item} sessions={sessions} actions={actions} {...handlers} /> : null}
592
+ {sheet === "acknowledge" ? <AcknowledgeSheet item={item} onReact={(ids) => (setSheet(null), actions.acknowledge(item, ids))} onClose={() => setSheet(null)} /> : null}
593
+ {sheet && typeof sheet === "object" ? (
594
+ <MenuSheet title={item.title} anchor={sheet.anchor} groups={menuGroups(item, sessions, sheet.kind, actions, perform, () => setSheet(null))} onClose={() => setSheet(null)} />
576
595
  ) : null}
577
- </View>
578
- {styles.compact ? null : buttons}
579
- </View>
580
- {sheet === "item" ? (
581
- <ItemSheet item={item} agent={agent} actions={actions} {...handlers} />
582
- ) : null}
583
- {sheet === "acknowledge" ? <AcknowledgeSheet item={item} onReact={(ids) => (setSheet(null), actions.acknowledge(item, ids))} onClose={() => setSheet(null)} /> : null}
584
- {sheet && typeof sheet === "object" ? <SessionOptions item={item} kind={sheet.options} actions={actions} onClose={() => setSheet(null)} /> : null}
585
- </View>
596
+ </>
597
+ }
598
+ />
586
599
  );
587
600
  }
588
601
 
602
+ // A split button's menu. With sessions open: each of them, then starting a new one. Without: the action with options [SES-02, SES-03].
603
+ function menuGroups(
604
+ item: Item,
605
+ sessions: AgentSummary[],
606
+ kind: SessionKind | undefined,
607
+ actions: Actions,
608
+ perform: (action: ActionId) => void,
609
+ close: () => void,
610
+ ): MenuGroup[] {
611
+ const withOptions = (action: ActionId | undefined, sessionKind: SessionKind): SheetEntry => {
612
+ const label = action ? actionLabel(action, item) : "Start session";
613
+ return {
614
+ key: `${action ?? "start"}-options`,
615
+ icon: "agent",
616
+ label: `${label} with options…`,
617
+ detail: "Choose the workspace, agent profile and prompt first",
618
+ onPress: () => (close(), actions.startWithOptions({ itemKey: item.key, title: `${label}: ${item.title}`, kind: sessionKind, target: item.target })),
619
+ };
620
+ };
621
+ const sessionActions = item.actions.filter((action) => ACTION_SESSION[action]);
622
+ if (sessions.length === 0) {
623
+ const action = sessionActions.find((candidate) => ACTION_SESSION[candidate] === kind);
624
+ return [{ entries: [withOptions(action, kind ?? fallbackKind(item))] }];
625
+ }
626
+ const start = sessionActions.flatMap((action): SheetEntry[] => [
627
+ { key: action, icon: "agent", label: actionLabel(action, item), detail: actionDetail(action as Exclude<ActionId, "rerun">, item), onPress: () => perform(action) },
628
+ withOptions(action, ACTION_SESSION[action]!),
629
+ ]);
630
+ return [
631
+ sessionsGroup(sessions, (agentId) => (close(), actions.openAgent(agentId))),
632
+ { title: "Start a new one", entries: start.length ? start : [withOptions(undefined, fallbackKind(item))] },
633
+ ];
634
+ }
635
+
589
636
  interface SheetHandlers {
590
637
  onPerform: (action: ActionId) => void;
591
- onOptions: (kind: SessionKind) => void;
638
+ onMenu: (kind?: SessionKind) => (anchor: Anchor | undefined) => void;
592
639
  onClose: () => void;
593
640
  }
594
641
 
595
642
  // What the card already knows on top, then every action, then what's fetched when it opens, so nothing jumps as it loads [ATT-06, GH-01].
596
- function ItemSheet({ item, agent, actions, ...handlers }: { item: Item; agent?: AgentSummary; actions: Actions } & SheetHandlers) {
643
+ function ItemSheet({ item, sessions, actions, ...handlers }: { item: Item; sessions: AgentSummary[]; actions: Actions } & SheetHandlers) {
597
644
  const checks = item.actions.includes("rerun");
598
645
  const details = useQuery({
599
646
  queryKey: ["attention-span", "details", item.key, checks],
@@ -615,7 +662,7 @@ function ItemSheet({ item, agent, actions, ...handlers }: { item: Item; agent?:
615
662
  {item.children.length > 0 ? <StackLine rows={item.children} merged={!!item.closedAt} links /> : null}
616
663
  </>
617
664
  }
618
- entries={sheetEntries(item, agent, actions, handlers, details)}
665
+ entries={sheetEntries(item, sessions, actions, handlers, details)}
619
666
  bottom={<DetailLines details={extra} loading={details.isLoading} error={details.error} linkedLabel={item.kind === "issue" ? "PR" : "Closes"} />}
620
667
  />
621
668
  );
@@ -624,26 +671,31 @@ function ItemSheet({ item, agent, actions, ...handlers }: { item: Item; agent?:
624
671
  // Everything an item's sheet offers, each saying what it will do [ATT-06]. Rerun's line needs the fetched checks.
625
672
  function sheetEntries(
626
673
  item: Item,
627
- agent: AgentSummary | undefined,
674
+ sessions: AgentSummary[],
628
675
  actions: Actions,
629
- { onPerform, onOptions, onClose }: SheetHandlers,
676
+ { onPerform, onMenu, onClose }: SheetHandlers,
630
677
  details?: { data?: { failing: FailingChecks[] }; isLoading: boolean },
631
678
  ): SheetEntry[] {
632
679
  const inDoing = !item.section.startsWith("wait_") && item.section !== "done" && item.section !== "reviewed";
633
680
  const close = (then: () => void) => () => (onClose(), then());
634
681
 
635
- const entries: SheetEntry[] = [];
636
- let continued = false;
682
+ // An open session first; starting another is in its menu [SES-03].
683
+ const entries: SheetEntry[] = sessions.length
684
+ ? [openSessionEntry(sessions, (agentId) => close(() => actions.openAgent(agentId))(), { label: "Session choices", onPress: onMenu() })]
685
+ : [];
637
686
  for (const action of item.actions) {
638
687
  const kind = ACTION_SESSION[action];
639
688
  const label = actionLabel(action, item);
640
- if (kind && agent) {
641
- // One session per item: continue it instead of starting another [SES-03].
642
- if (!continued) entries.push({ key: action, icon: "agent", label: CONTINUE_LABELS[kind], detail: `Opens the session (${agentSignal(agent).text})`, onPress: close(() => actions.openAgent(agent.id)) });
643
- continued = true;
644
- } else if (kind) {
645
- entries.push({ key: action, icon: "agent", label, detail: actionDetail(action as Exclude<ActionId, "rerun">, item), onPress: () => onPerform(action) });
646
- entries.push({ key: `${action}-options`, icon: "agent", label: `${label} with options…`, detail: "Choose the workspace, agent profile and prompt first", onPress: () => onOptions(kind) });
689
+ if (kind && sessions.length) continue;
690
+ else if (kind) {
691
+ entries.push({
692
+ key: action,
693
+ icon: "agent",
694
+ label,
695
+ detail: actionDetail(action as Exclude<ActionId, "rerun">, item),
696
+ onPress: () => onPerform(action),
697
+ menu: { label: `${label} choices`, onPress: onMenu(kind) },
698
+ });
647
699
  } else if (action === "rerun") {
648
700
  const { detail, runIds } = rerunEntry(details?.data?.failing, details?.isLoading ?? true);
649
701
  entries.push({ key: action, icon: ACTION_ICONS.rerun, label, detail, disabled: runIds.length === 0, onPress: close(() => actions.rerun(item, runIds)) });
@@ -674,7 +726,10 @@ function AcknowledgeSheet({ item, onReact, onClose }: { item: Item; onReact: (id
674
726
  <Modal title={`Acknowledge: ${item.title}`} open onOpenChange={(open) => (open ? null : onClose())}>
675
727
  <Modal.Content>
676
728
  <KeepStyles styles={styles}>
677
- <Text style={styles.muted}>A πŸ‘ tells them you've seen it, and clears it from your list.</Text>
729
+ <View style={styles.row}>
730
+ <TablerIcon name="thumbUp" size={14} />
731
+ <Text style={[styles.muted, { flexShrink: 1 }]}>Tells them you've seen it, and clears it from your list.</Text>
732
+ </View>
678
733
  {comments.map((c) => (
679
734
  <Pressable
680
735
  key={c.id}
@@ -695,7 +750,9 @@ function AcknowledgeSheet({ item, onReact, onClose }: { item: Item; onReact: (id
695
750
  ))}
696
751
  <View style={styles.wrap}>
697
752
  <Button
698
- label={`πŸ‘ ${picked.size} comment${picked.size === 1 ? "" : "s"}`}
753
+ label={`${picked.size} comment${picked.size === 1 ? "" : "s"}`}
754
+ icon="thumbUp"
755
+ accessibilityLabel={`Acknowledge ${picked.size} comment${picked.size === 1 ? "" : "s"}`}
699
756
  variant="solid"
700
757
  disabled={picked.size === 0}
701
758
  onPress={() => onReact(comments.filter((c) => picked.has(c.id)).map((c) => c.id))}
@@ -741,13 +798,12 @@ function Sections({ sections, actions, empty }: { sections: Section[]; actions:
741
798
  }
742
799
 
743
800
  function Card({ items, actions }: { items: Item[]; actions: Actions }) {
744
- const styles = useStyles();
745
801
  return (
746
- <View style={styles.card}>
802
+ <CardList>
747
803
  {items.map((item, index) => (
748
804
  <ItemRow key={item.key} item={item} first={index === 0} actions={actions} />
749
805
  ))}
750
- </View>
806
+ </CardList>
751
807
  );
752
808
  }
753
809
 
@@ -827,7 +883,7 @@ function StackLine({ rows, merged, links = false }: { rows: SubRow[]; merged: bo
827
883
  <StackRow key={row.key} url={row.url} number={row.number} link={links}>
828
884
  <View style={{ width: 16, alignItems: "center" }}>
829
885
  <View style={{ width: 2, flex: 1, backgroundColor: index === 0 ? "transparent" : styles.c.border }} />
830
- <TablerIcon name={merged ? "merge" : row.draft ? "draft" : "pr"} size={14} color={merged ? styles.c.accent : row.draft ? styles.c.foregroundMuted : styles.c.statusSuccess} />
886
+ <TablerIcon name={merged ? "merge" : row.draft ? "draft" : "pr"} size={14} color={merged ? styles.c.statusSuccess : row.draft ? styles.c.foregroundMuted : styles.c.statusSuccess} />
831
887
  <View style={{ width: 2, flex: 1, backgroundColor: index === rows.length - 1 ? "transparent" : styles.c.border }} />
832
888
  </View>
833
889
  <View style={{ flex: 1, paddingVertical: 3, gap: 2 }}>
@@ -865,13 +921,13 @@ function StackRow({ url, number, link, children }: { url: string; number: number
865
921
  }
866
922
 
867
923
  // Session options in a modal: a bottom sheet on phones [SES-02].
868
- function SessionOptions({ item, kind, actions, onClose }: { item: Item; kind: SessionKind; actions: Actions; onClose: () => void }) {
924
+ function SessionOptions({ spec, actions, onClose }: { spec: OptionsSpec; actions: Actions; onClose: () => void }) {
869
925
  const styles = useStyles();
870
926
  const paseo = usePaseo();
871
927
  const toast = useToast();
872
- const { target } = item;
928
+ const { itemKey, kind, target } = spec;
873
929
  const options = useQuery({
874
- queryKey: ["attention-span", "options", item.key, kind],
930
+ queryKey: ["attention-span", "options", itemKey, kind],
875
931
  queryFn: async () => {
876
932
  const [{ context }, profiles, checkout, defaults] = await Promise.all([
877
933
  actions.fetchContext({ kind, target }),
@@ -895,7 +951,8 @@ function SessionOptions({ item, kind, actions, onClose }: { item: Item; kind: Se
895
951
  if (!data) return;
896
952
  setStarting(true);
897
953
  try {
898
- await actions.started(await startSession(paseo, { itemKey: item.key, kind, target, prompt: prompt ?? data.prompt, config: actions.config, checkout: data.checkout, profileId, workspaceId }));
954
+ await spec.before?.();
955
+ await actions.started(await startSession(paseo, { itemKey, kind, target, prompt: prompt ?? data.prompt, config: actions.config, checkout: data.checkout, profileId, workspaceId }));
899
956
  onClose();
900
957
  } catch (error) {
901
958
  toast.error(`Starting the session failed: ${(error as Error).message}`);
@@ -905,10 +962,10 @@ function SessionOptions({ item, kind, actions, onClose }: { item: Item; kind: Se
905
962
  }
906
963
 
907
964
  return (
908
- <Modal title={`${actionLabel(item.actions.find((a) => ACTION_SESSION[a] === kind) ?? "start", item)}: ${item.title}`} open onOpenChange={(open) => (open ? null : onClose())}>
965
+ <Modal title={spec.title} open onOpenChange={(open) => (open ? null : onClose())}>
909
966
  <Modal.Content>
910
967
  <KeepStyles styles={styles}>
911
- {options.isLoading ? <Text style={styles.muted}>Loading context…</Text> : null}
968
+ {options.isLoading ? <Loading text="Loading context…" /> : null}
912
969
  {!options.isLoading && !data ? <Text style={styles.danger}>{(options.error as Error)?.message ?? "No options"}</Text> : null}
913
970
  {data && !data.checkout.project ? <Text style={styles.danger}>{noProjectMessage(data.checkout, target)}</Text> : null}
914
971
  {data?.checkout.project ? (
@@ -952,7 +1009,7 @@ function CodeRepoPicker({ issueRepo, missing, onPick, onClose }: { issueRepo: st
952
1009
  <KeepStyles styles={styles}>
953
1010
  <View style={{ gap: 10 }}>
954
1011
  <Text style={styles.text}>No Paseo project has {missing} as its GitHub remote. Pick the project that holds the code for issues in {issueRepo}.</Text>
955
- {projects.isLoading ? <Text style={styles.muted}>Loading projects…</Text> : null}
1012
+ {projects.isLoading ? <Loading text="Loading projects…" /> : null}
956
1013
  {projects.data?.length === 0 ? <Text style={styles.danger}>No Paseo project has a GitHub remote. Add the code repository as a project first.</Text> : null}
957
1014
  <View style={styles.wrap}>
958
1015
  {projects.data?.map((project) => (