@andrioid/paseo-attention-span 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/OVERVIEW.md +7 -1
  2. package/client/attention-screen.tsx +74 -1176
  3. package/client/coverage-settings.tsx +5 -4
  4. package/client/data.ts +4 -2
  5. package/client/feedback.tsx +21 -25
  6. package/client/history.tsx +17 -50
  7. package/client/item-actions.ts +363 -0
  8. package/client/item-row.tsx +450 -0
  9. package/client/new-issue.tsx +244 -0
  10. package/client/next-up.tsx +36 -183
  11. package/client/pickers.tsx +237 -0
  12. package/client/session-menu.ts +3 -11
  13. package/client/sessions.ts +58 -57
  14. package/client/setup.tsx +2 -1
  15. package/client/sheet.tsx +92 -15
  16. package/client/still.tsx +70 -27
  17. package/client/ui.tsx +23 -14
  18. package/client/wrap-up.tsx +151 -85
  19. package/docs/architecture.md +22 -11
  20. package/docs/screenshots/desktop-dark-doing-acknowledge.png +0 -0
  21. package/docs/screenshots/desktop-dark-doing-clear.png +0 -0
  22. package/docs/screenshots/desktop-dark-doing-issue-sheet.png +0 -0
  23. package/docs/screenshots/desktop-dark-doing-reviewers.png +0 -0
  24. package/docs/screenshots/desktop-dark-doing-sheet.png +0 -0
  25. package/docs/screenshots/desktop-dark-doing-wrap-dirty.png +0 -0
  26. package/docs/screenshots/desktop-dark-doing-wrap-multi.png +0 -0
  27. package/docs/screenshots/desktop-dark-doing-wrap.png +0 -0
  28. package/docs/screenshots/desktop-dark-doing.png +0 -0
  29. package/docs/screenshots/desktop-dark-next-up-setup.png +0 -0
  30. package/docs/screenshots/desktop-dark-next-up.png +0 -0
  31. package/docs/screenshots/desktop-dark-settings.png +0 -0
  32. package/docs/screenshots/phone-dark-doing.png +0 -0
  33. package/docs/screenshots/phone-light-next-up-filtered.png +0 -0
  34. package/index.client.tsx +19 -0
  35. package/index.server.ts +43 -26
  36. package/package.json +3 -1
  37. package/requirements.yaml +11 -3
  38. package/server/actions.ts +2 -1
  39. package/server/archive.ts +146 -67
  40. package/server/archived.ts +12 -16
  41. package/server/changes.ts +34 -54
  42. package/server/classify.ts +142 -136
  43. package/server/feedback.ts +2 -6
  44. package/server/fetch.ts +262 -0
  45. package/server/fixture.ts +91 -7
  46. package/server/github-types.ts +3 -1
  47. package/server/markdown.ts +3 -1
  48. package/server/port.ts +46 -0
  49. package/server/queries.ts +33 -23
  50. package/server/service.ts +155 -272
  51. package/server/setup.ts +15 -14
  52. package/server/store.ts +94 -80
  53. package/server/update.ts +34 -13
  54. package/server/view.ts +16 -15
  55. package/shared/archive.ts +116 -13
  56. package/shared/attention.ts +50 -18
  57. package/shared/changes.ts +2 -1
  58. package/shared/config.ts +2 -6
  59. package/shared/drafting.ts +17 -0
  60. package/shared/feedback.ts +6 -5
  61. package/shared/format.ts +2 -1
  62. package/shared/history-report.ts +2 -1
  63. package/shared/item-sessions.ts +76 -0
  64. package/shared/item-view.ts +223 -0
  65. package/shared/linked-sessions.ts +59 -8
  66. package/shared/names.ts +17 -0
  67. package/shared/new-issue.ts +129 -0
  68. package/shared/next-up-filter.ts +137 -0
  69. package/shared/paging.ts +16 -0
  70. package/shared/rpc.ts +23 -10
  71. package/shared/setup.ts +3 -1
  72. package/shared/still.ts +28 -7
  73. package/shared/wrap-up.ts +20 -23
package/client/still.tsx CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Icon } from "@getpaseo/plugin/client/ui";
2
- import { useEffect, useRef, useState } from "react";
3
- import { AccessibilityInfo, Animated, Easing, Platform, Text, View } from "react-native";
2
+ import { type ReactNode, useEffect, useRef, useState } from "react";
3
+ import { AccessibilityInfo, Animated, Easing, Platform, Pressable, Text, View } from "react-native";
4
4
  import { themeName } from "../shared/feedback";
5
5
  import { type Scene, sceneAt } from "../shared/still";
6
- import { useStyles } from "./ui";
6
+ import { Button, useStyles } from "./ui";
7
7
 
8
- // Doing with nothing in it: a horizon that follows the clock, and nothing that asks for anything [ATT-18].
8
+ // A tab with nothing in it: a horizon that follows the clock, and nothing that asks for anything [ATT-18].
9
+ // History, Waiting and Next up each add one thing on the shore [HIS-08, WAI-04, NXT-13].
9
10
  // It settles in on every arrival, then stays still; the hour changing crossfades it.
10
11
 
11
12
  // One tint per time of day, darker on light themes so it holds up on white.
@@ -20,31 +21,46 @@ const H = 110;
20
21
  const svg = (body: string) =>
21
22
  `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round">${body}</svg>`;
22
23
 
23
- const SKY: Record<Scene, string> = {
24
- morning: svg(`<path d="M100 66a20 20 0 0 1 40 0"/>`),
25
- midday: svg(`<circle cx="120" cy="30" r="16"/>`),
26
- evening: svg(`<path d="M88 66a32 32 0 0 1 64 0"/>`),
27
- night: svg(
28
- `<path d="M126 18a16 16 0 1 0 14 22a12.5 12.5 0 0 1 -14 -22z"/>` +
29
- [
24
+ // The sun or moon, moved right by `dx` to make room for a shore; the stars stay put.
25
+ const sky = (scene: Scene, dx: number) =>
26
+ svg(
27
+ `<g transform="translate(${dx} 0)">${SUN[scene]}</g>` +
28
+ (scene === "night" ? STARS : ""),
29
+ );
30
+ const SUN: Record<Scene, string> = {
31
+ morning: `<path d="M100 66a20 20 0 0 1 40 0"/>`,
32
+ midday: `<circle cx="120" cy="30" r="16"/>`,
33
+ evening: `<path d="M88 66a32 32 0 0 1 64 0"/>`,
34
+ night: `<path d="M126 18a16 16 0 1 0 14 22a12.5 12.5 0 0 1 -14 -22z"/>`,
35
+ };
36
+ const STARS = [
30
37
  [70, 24],
31
38
  [168, 16],
32
39
  [190, 40],
33
40
  [52, 46],
34
41
  ]
35
- .map(([x, y]) => `<circle cx="${x}" cy="${y}" r="1" fill="currentColor" stroke="none" opacity=".6"/>`)
36
- .join(""),
37
- ),
38
- };
42
+ .map(([x, y]) => `<circle cx="${x}" cy="${y}" r="1" fill="currentColor" stroke="none" opacity=".6"/>`)
43
+ .join("");
39
44
 
40
45
  // The sun's light on the water, fading downwards; wider under a low sun.
41
46
  const WIDTHS: Record<Scene, number[]> = { morning: [40, 26, 12], midday: [24, 16, 8], evening: [56, 40, 20], night: [30, 18, 8] };
42
- const WATER: Record<Scene, string> = Object.fromEntries(
43
- (Object.keys(WIDTHS) as Scene[]).map((scene) => [
44
- scene,
45
- svg(WIDTHS[scene].map((width, i) => `<path d="M${W / 2 - width / 2} ${76 + i * 8}h${width}" stroke-opacity="${[0.45, 0.28, 0.15][i]}"/>`).join("")),
46
- ]),
47
- ) as Record<Scene, string>;
47
+ const water = (scene: Scene, dx: number) =>
48
+ svg(WIDTHS[scene].map((width, i) => `<path d="M${W / 2 + dx - width / 2} ${76 + i * 8}h${width}" stroke-opacity="${[0.45, 0.28, 0.15][i]}"/>`).join(""));
49
+
50
+ // One thing on the shore, left of the sun, in the line's muted colour: History's bench to look back from, Waiting's
51
+ // jetty with nothing tied to it, Next up's signpost with blank boards. `dx` moves the sun right to make room.
52
+ export type Shore = "bench" | "jetty" | "signpost";
53
+ const SHORES: Record<Shore, { dx: number; svg: string }> = {
54
+ bench: { dx: 36, svg: svg(`<path d="M36 57h28"/><path d="M38 57l-4-14"/><path d="M40 57v9M62 57v9"/>`) },
55
+ jetty: {
56
+ dx: 30,
57
+ svg: svg(`<path d="M20 58h82"/>` + [28, 50, 72, 94].map((x) => `<path d="M${x} 58v14"/><path d="M${x} 78v3" stroke-opacity=".35"/>`).join("")),
58
+ },
59
+ signpost: {
60
+ dx: 40,
61
+ svg: svg(`<path d="M64 66v-34"/><path d="M50 36h26l5 4-5 4h-26z"/><path d="M78 48h-26l-5 4 5 4h26z" stroke-opacity=".6"/>`),
62
+ },
63
+ };
48
64
 
49
65
  const LINE = { svg: svg(`<path d="M20 66h200"/>`) };
50
66
 
@@ -52,8 +68,18 @@ const SETTLE_MS = 700;
52
68
  const CROSSFADE_MS = 4000;
53
69
  const native = Platform.OS !== "web";
54
70
 
55
- export function Still() {
71
+ // What the scene says, and at most one way on: a calm button, or a quieter link in the action colour, which stays
72
+ // readable where the sun's tints are too pale for small text.
73
+ type Way = { label: string; onPress: () => void; link?: boolean };
74
+
75
+ export function Still({
76
+ shore,
77
+ title = "Nothing's on you.",
78
+ line = "Enjoy the quiet.",
79
+ way,
80
+ }: { shore?: Shore; title?: string; line?: string; way?: Way } = {}) {
56
81
  const styles = useStyles();
82
+ const dx = shore ? SHORES[shore].dx : 0;
57
83
  const theme = themeName(styles.c.surface0);
58
84
  const width = styles.compact ? 200 : 240;
59
85
  const height = Math.round((width * H) / W);
@@ -95,6 +121,8 @@ export function Still() {
95
121
 
96
122
  const skyIn = { opacity: arrive.interpolate({ inputRange: [0, 0.65, 1], outputRange: [0, 1, 1] }), transform: [{ translateY: arrive.interpolate({ inputRange: [0, 0.65, 1], outputRange: [6, 0, 0] }) }] };
97
123
  const waterIn = { opacity: arrive.interpolate({ inputRange: [0, 0.35, 1], outputRange: [0, 0, 1] }) };
124
+ // The shore settles in with the water, rising a little.
125
+ const shoreIn = { opacity: waterIn.opacity, transform: [{ translateY: arrive.interpolate({ inputRange: [0, 0.35, 1], outputRange: [3, 3, 0] }) }] };
98
126
  const fadeOut = fade.interpolate({ inputRange: [0, 1], outputRange: [1, 0] });
99
127
 
100
128
  // SvgXml draws a size × size square; the canvas sits in its middle, so crop the square to the canvas.
@@ -105,8 +133,8 @@ export function Still() {
105
133
  );
106
134
  const scenery = (shown: Scene, opacity: Animated.AnimatedInterpolation<number> | Animated.Value) => (
107
135
  <Animated.View key={shown} style={{ position: "absolute", inset: 0, opacity }}>
108
- <Animated.View style={[{ position: "absolute", inset: 0 }, skyIn]}>{layer({ svg: SKY[shown] }, TINTS[theme][shown])}</Animated.View>
109
- <Animated.View style={[{ position: "absolute", inset: 0 }, waterIn]}>{layer({ svg: WATER[shown] }, TINTS[theme][shown])}</Animated.View>
136
+ <Animated.View style={[{ position: "absolute", inset: 0 }, skyIn]}>{layer({ svg: sky(shown, dx) }, TINTS[theme][shown])}</Animated.View>
137
+ <Animated.View style={[{ position: "absolute", inset: 0 }, waterIn]}>{layer({ svg: water(shown, dx) }, TINTS[theme][shown])}</Animated.View>
110
138
  </Animated.View>
111
139
  );
112
140
 
@@ -114,16 +142,31 @@ export function Still() {
114
142
  // Upper two-fifths: a little above the middle, so it reads as a place, not a floating notice.
115
143
  <View style={{ flex: 1, minHeight: styles.compact ? 300 : 360 }}>
116
144
  <View style={{ flex: 2 }} />
117
- <View accessible accessibilityLabel="Nothing needs you right now." style={{ alignItems: "center", gap: 12 }}>
145
+ <View style={{ alignItems: "center", gap: 12 }}>
118
146
  <View style={{ width, height, overflow: "hidden" }} importantForAccessibility="no-hide-descendants" accessibilityElementsHidden>
119
147
  <View style={{ position: "absolute", inset: 0, opacity: 0.6 }}>{layer(LINE, styles.c.foregroundMuted)}</View>
120
148
  {previous ? scenery(previous, fadeOut) : null}
121
149
  {scenery(scene, fade)}
150
+ {shore ? (
151
+ <Animated.View style={[{ position: "absolute", inset: 0 }, shoreIn]}>{layer(SHORES[shore], styles.c.foregroundMuted)}</Animated.View>
152
+ ) : null}
122
153
  </View>
123
- <Text style={{ color: styles.c.foreground, fontSize: 17, fontWeight: "600", marginTop: 6 }}>Nothing's on you.</Text>
124
- <Text style={[styles.muted, { fontSize: 13 }]}>Enjoy the quiet.</Text>
154
+ <View accessible style={{ alignItems: "center", gap: 12 }}>
155
+ <Text style={{ color: styles.c.foreground, fontSize: 17, fontWeight: "600", marginTop: 6, textAlign: "center" }}>{title}</Text>
156
+ <Text style={[styles.muted, { fontSize: 13, textAlign: "center" }]}>{line}</Text>
157
+ </View>
158
+ {way ? <WayOn way={way} color={styles.action} /> : null}
125
159
  </View>
126
160
  <View style={{ flex: 3 }} />
127
161
  </View>
128
162
  );
129
163
  }
164
+
165
+ function WayOn({ way, color }: { way: Way; color: string }): ReactNode {
166
+ if (!way.link) return <View style={{ marginTop: 8 }}><Button label={way.label} icon="settings" onPress={way.onPress} /></View>;
167
+ return (
168
+ <Pressable accessibilityRole="link" onPress={way.onPress} hitSlop={8} style={{ marginTop: 8 }}>
169
+ <Text style={{ color, fontSize: 13 }}>{way.label} ›</Text>
170
+ </Pressable>
171
+ );
172
+ }
package/client/ui.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PluginScreenProps } from "@getpaseo/plugin/client";
2
2
  import { copyText, Icon, useToast } from "@getpaseo/plugin/client/ui";
3
3
  import { createContext, type ReactNode, type RefObject, useContext, useEffect, useMemo, useRef, useState } from "react";
4
- import { ActivityIndicator, Animated, Dimensions, Easing, Image, Platform, Pressable, type StyleProp, Text, View, type ViewStyle } from "react-native";
4
+ import { ActivityIndicator, Animated, Dimensions, Easing, Image, Platform, Pressable, type PressableProps, type StyleProp, Text, View, type ViewStyle } from "react-native";
5
5
  import type { Chip } from "../shared/attention";
6
6
  import { HINT_GAP, type HintPlacement, hintPlacement } from "../shared/hint";
7
7
  import { ICONS, type IconName } from "./icons";
@@ -341,6 +341,22 @@ export function Button({
341
341
  );
342
342
  }
343
343
 
344
+ // Filter, with how many ticks are on [NXT-03, HIS-07].
345
+ export function FilterButton({ count, onPress }: { count: number; onPress: () => void }) {
346
+ return <Button label={count ? `Filter · ${count}` : "Filter"} accessibilityLabel={count ? `Filter, ${count} on` : "Filter"} icon="filter" variant={count ? "calm" : "ghost"} onPress={onPress} />;
347
+ }
348
+
349
+ // A tick box, then what it's for: filters and pickers. Mixed is a project with some of its statuses ticked [NXT-12].
350
+ export function CheckRow({ checked, label, children, ...pressable }: { checked: boolean | "mixed"; label: string; children: ReactNode } & Omit<PressableProps, "children">) {
351
+ const styles = useStyles();
352
+ return (
353
+ <Pressable accessibilityRole="checkbox" accessibilityState={{ checked, disabled: !!pressable.disabled }} aria-checked={checked} accessibilityLabel={label} {...pressable}>
354
+ <TablerIcon name={checked === "mixed" ? "squareMinus" : checked ? "squareCheck" : "square"} size={18} color={checked ? styles.action : styles.c.foregroundMuted} />
355
+ {children}
356
+ </Pressable>
357
+ );
358
+ }
359
+
344
360
  // Sentence case, with the count as quiet text.
345
361
  // The icon may be a picture instead, like the avatar of whom Waiting's work waits on.
346
362
  export function SectionHeader({ icon, title, count, action }: { icon: IconName | ReactNode; title: string; count: number; action?: ReactNode }) {
@@ -357,19 +373,12 @@ export function SectionHeader({ icon, title, count, action }: { icon: IconName |
357
373
  );
358
374
  }
359
375
 
360
- // A group that opens in place, like a week's reviews in History: a chevron, its name and count. Each opens on its own, so
361
- // they don't read as a choice between them [HIS-02, HIS-06].
362
- export function Disclosure({ label, count, open, onPress }: { label: string; count: number; open: boolean; onPress: () => void }) {
363
- const styles = useStyles();
364
- return (
365
- <Pressable accessibilityRole="button" accessibilityLabel={`${label}, ${count}`} accessibilityState={{ expanded: open }} onPress={onPress} hitSlop={6} style={[styles.row, { gap: 6, paddingVertical: 4 }]}>
366
- <TablerIcon name={open ? "chevronDown" : "chevronRight"} size={14} />
367
- <Text style={{ color: styles.c.foreground, fontSize: 13, fontWeight: "600" }}>
368
- {label}
369
- <Text style={{ color: styles.c.foregroundMuted, fontWeight: "400" }}> · {count}</Text>
370
- </Text>
371
- </Pressable>
372
- );
376
+ // A theme colour, see-through, so a badge reads on any surface; colours that aren't #rrggbb fall back to none.
377
+ export function tint(color: string, alpha: number): string {
378
+ const hex = /^#([0-9a-f]{6})/i.exec(color)?.[1];
379
+ if (!hex) return "transparent";
380
+ const [r, g, b] = [0, 2, 4].map((at) => parseInt(hex.slice(at, at + 2), 16));
381
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
373
382
  }
374
383
 
375
384
  // Copy text and say so, since an icon-only button gives no other sign it worked.
@@ -1,16 +1,17 @@
1
1
  import { useState } from "react";
2
2
  import { Text, View } from "react-native";
3
3
  import type { AgentSummary, WrapItem } from "../shared/attention";
4
- import type { ArchiveOutcome, UnsavedSession } from "../shared/archive";
4
+ import { type ArchiveOutcome, type KeptRow, keptText, sheetLines, type UnsavedSession, unsavedWords } from "../shared/archive";
5
5
  import { allWrapBusy, wrapBusy } from "../shared/got-it";
6
- import { cleanSingle, sessionCleanliness, unsavedText } from "../shared/wrap-up";
6
+ import { cleanSingle, sessionCleanliness, sessionUnsaved } from "../shared/wrap-up";
7
7
  import { CardList, CardRow } from "./card";
8
8
  import { stateMark } from "./mark";
9
- import { Modal } from "./sheet";
10
- import { Button, KeepStyles, SectionHeader, TablerIcon, useStyles } from "./ui";
9
+ import { Dialog } from "./sheet";
10
+ import { Button, SectionHeader, TablerIcon, useStyles } from "./ui";
11
11
 
12
12
  // Doing's Wrap up: finished or out-of-my-hands work whose sessions are still open, and archiving them [ATT-22]. The screen
13
- // assembles the rows and runs the archive; these draw them and ask before archiving anything unsaved.
13
+ // assembles the rows and runs the archive; these draw them and ask before archiving anything unsaved or closing a terminal,
14
+ // in a sheet shaped like Paseo's own. A worktree that stayed lingers as a row saying why.
14
15
 
15
16
  interface RowProps {
16
17
  busy: ReadonlySet<string>;
@@ -18,11 +19,17 @@ interface RowProps {
18
19
  // Previews have made-up sessions: their snapshot is the answer, as there's no daemon to ask.
19
20
  fixture: boolean;
20
21
  openAgent: (agentId: string) => void;
21
- onArchive: (item: WrapItem, confirm: boolean) => Promise<ArchiveOutcome | null>;
22
+ onArchive: (item: WrapItem, confirm: boolean, terminals?: string[]) => Promise<ArchiveOutcome | null>;
23
+ }
24
+
25
+ interface KeptProps {
26
+ kept: KeptRow[];
27
+ onArchiveWorktree: (row: KeptRow, confirm: boolean, terminals?: string[]) => Promise<ArchiveOutcome | null>;
28
+ onDismissKept: (row: KeptRow) => void;
22
29
  }
23
30
 
24
31
  // Finished or out-of-my-hands work whose Paseo sessions are all idle: the cleanup Doing owns [ATT-22].
25
- export function WrapUp({ items, onArchiveAll, ...row }: { items: WrapItem[]; onArchiveAll: () => Promise<void> } & RowProps) {
32
+ export function WrapUp({ items, onArchiveAll, kept, onArchiveWorktree, onDismissKept, ...row }: { items: WrapItem[]; onArchiveAll: () => Promise<void> } & RowProps & KeptProps) {
26
33
  const styles = useStyles();
27
34
  const clean = items.filter(cleanSingle);
28
35
  return (
@@ -49,6 +56,18 @@ export function WrapUp({ items, onArchiveAll, ...row }: { items: WrapItem[]; onA
49
56
  {items.map((item, index) => (
50
57
  <WrapRow key={item.key} item={item} first={index === 0} {...row} />
51
58
  ))}
59
+ {kept.map((keptRow, index) => (
60
+ <KeptWorktreeRow
61
+ key={keptRow.workspaceId}
62
+ row={keptRow}
63
+ first={items.length === 0 && index === 0}
64
+ busy={row.busy.has(`kept:${keptRow.workspaceId}`)}
65
+ login={row.login}
66
+ openSession={row.openAgent}
67
+ onArchive={onArchiveWorktree}
68
+ onDismiss={onDismissKept}
69
+ />
70
+ ))}
52
71
  </CardList>
53
72
  </View>
54
73
  );
@@ -65,29 +84,37 @@ function WrapRow({ item, first, busy, login, fixture, openAgent: openSession, on
65
84
  const { sessions } = item.wrap;
66
85
  const [sheet, setSheet] = useState<"multi" | "dirty" | null>(null);
67
86
  const [unsaved, setUnsaved] = useState<UnsavedSession[]>([]);
87
+ // The terminals the confirm sheet names, sent back with it: a terminal opened since brings the sheet back [ATT-22].
88
+ const [terminals, setTerminals] = useState<string[]>([]);
89
+ // The worktrees the sheet's archive removes, by name, for its title.
90
+ const [leaving, setLeaving] = useState<string[]>([]);
68
91
  const dirty = sessions.some((session) => sessionCleanliness(session) === "dirty");
69
92
  const press = async () => {
70
93
  if (sessions.length > 1) return setSheet("multi");
71
94
  // A preview has no daemon to ask; its made-up snapshot is the answer. Elsewhere the server checks git too, so the sheet
72
95
  // can name the files and commits it found.
73
96
  if (sessionCleanliness(sessions[0]) !== "clean" && fixture) {
74
- setUnsaved([dirtyFallback(sessions[0])]);
97
+ const workspace = sessions[0].workspace;
98
+ setUnsaved([readingOf(sessions[0])]);
99
+ setLeaving(workspace?.kind === "worktree" ? [workspace.name] : []);
75
100
  return setSheet("dirty");
76
101
  }
77
- const outcome = await onArchive(item, false);
102
+ asked(await onArchive(item, false));
103
+ };
104
+ const asked = (outcome: ArchiveOutcome | null) => {
78
105
  if (outcome && !outcome.ok && outcome.reason === "unsaved") {
79
106
  setUnsaved(outcome.sessions);
107
+ setTerminals(outcome.terminals);
108
+ setLeaving(outcome.leaving);
80
109
  setSheet("dirty");
81
110
  }
82
111
  };
83
- // The multi sheet asks the server first, like a single row; unsaved work it finds gets the confirm that names it [ATT-22].
112
+ // The multi sheet asks the server first, like a single row; unsaved work or open terminals it finds get the confirm that
113
+ // names them [ATT-22].
84
114
  const confirm = async (confirm: boolean) => {
85
- const outcome = await onArchive(item, confirm);
115
+ const outcome = await onArchive(item, confirm, confirm ? terminals : []);
86
116
  if (outcome?.ok) return setSheet(null);
87
- if (outcome && outcome.reason === "unsaved") {
88
- setUnsaved(outcome.sessions);
89
- setSheet("dirty");
90
- }
117
+ asked(outcome);
91
118
  };
92
119
  return (
93
120
  <CardRow
@@ -110,54 +137,44 @@ function WrapRow({ item, first, busy, login, fixture, openAgent: openSession, on
110
137
  secondary={[{ label: `Details for #${item.number}`, icon: "chevronRight", onPress: () => (sessions.length > 1 ? setSheet("multi") : sessions[0] ? openSession(sessions[0].id) : undefined) }]}
111
138
  overlay={
112
139
  sheet === "multi" ? (
113
- <Modal title={`Sessions on #${item.number}`} open onOpenChange={(open) => (open ? null : setSheet(null))}>
114
- <Modal.Content>
115
- <KeepStyles styles={styles}>
116
- <Text style={styles.muted}>
117
- {item.title} · {item.wrap.finish}
118
- </Text>
119
- <View style={[styles.card, { backgroundColor: styles.c.surface2 }]}>
120
- {sessions.map((session, index) => (
121
- <View key={session.id} style={[styles.row, { paddingVertical: 10, paddingHorizontal: 12 }, index > 0 ? styles.divider : null]}>
122
- <TablerIcon name="agent" size={16} />
123
- <View style={{ flex: 1, gap: 2 }}>
124
- <Text style={styles.text}>{session.title ?? "Session"}</Text>
125
- <Text style={styles.muted}>{sessionStateText(session)}</Text>
126
- </View>
127
- <Button label="Open" variant="ghost" onPress={() => openSession(session.id)} />
128
- </View>
129
- ))}
130
- </View>
131
- <Text style={styles.muted}>
132
- Archives {sessions.length} sessions. Their worktrees go too when nothing else lives in them
133
- {sessions.some((session) => sessionCleanliness(session) === "unknown") ? "; the one that couldn't be checked may hold unsaved work" : ""}.
134
- </Text>
135
- <View style={[styles.row, { justifyContent: "flex-end" }]}>
136
- <Button label="Cancel" onPress={() => setSheet(null)} />
137
- <Button label={sessions.length === 2 ? "Archive both" : `Archive ${sessions.length}`} variant="danger" onPress={() => void confirm(false)} />
138
- </View>
139
- </KeepStyles>
140
- </Modal.Content>
141
- </Modal>
142
- ) : sheet === "dirty" ? (
143
- <Modal title={sessions.length > 1 ? `Archive the sessions on #${item.number}?` : `Archive the session on #${item.number}?`} open onOpenChange={(open) => (open ? null : setSheet(null))}>
144
- <Modal.Content>
145
- <KeepStyles styles={styles}>
146
- {(unsaved.length ? unsaved : [dirtyFallback(sessions[0])]).map((info) => (
147
- <View key={info.agentId} style={{ gap: 2 }}>
148
- <Text style={styles.text}>{info.title ?? "Session"}</Text>
149
- <Text style={{ color: styles.c.statusWarning, fontSize: 13 }}>
150
- {info.unknown ? "Couldn't check for unsaved changes. Archiving may remove the worktree." : `Its worktree has ${unsavedTextFrom(info)}. Archiving may remove them.`}
151
- </Text>
140
+ <Dialog title={`Sessions on #${item.number}`} onClose={() => setSheet(null)}>
141
+ <Text style={styles.muted}>
142
+ {item.title} · {item.wrap.finish}
143
+ </Text>
144
+ <View style={[styles.card, { backgroundColor: styles.c.surface2 }]}>
145
+ {sessions.map((session, index) => (
146
+ <View key={session.id} style={[styles.row, { paddingVertical: 10, paddingHorizontal: 12 }, index > 0 ? styles.divider : null]}>
147
+ <TablerIcon name="agent" size={16} />
148
+ <View style={{ flex: 1, gap: 2 }}>
149
+ <Text style={styles.text}>{session.title ?? "Session"}</Text>
150
+ <Text style={styles.muted}>{sessionStateText(session)}</Text>
151
+ {session.subAgents?.count ? (
152
+ <Text style={styles.muted}>
153
+ +{session.subAgents.count} sub-agent{session.subAgents.count === 1 ? "" : "s"}
154
+ </Text>
155
+ ) : null}
152
156
  </View>
153
- ))}
154
- <View style={[styles.row, { justifyContent: "flex-end" }]}>
155
- <Button label="Open session" icon="agent" variant="calm" onPress={() => openSession(unsaved[0]?.agentId ?? sessions[0].id)} />
156
- <Button label="Archive anyway" variant="danger" onPress={() => void confirm(true)} />
157
+ <Button label="Open" variant="ghost" onPress={() => openSession(session.id)} />
157
158
  </View>
158
- </KeepStyles>
159
- </Modal.Content>
160
- </Modal>
159
+ ))}
160
+ </View>
161
+ <Text style={styles.muted}>
162
+ Archives {sessions.length} sessions. Their worktrees go too when no other session lives in them, closing their terminals
163
+ {sessions.some((session) => sessionCleanliness(session) === "unknown") ? "; the one that couldn't be checked may hold unsaved work" : ""}.
164
+ </Text>
165
+ <View style={[styles.row, { justifyContent: "flex-end" }]}>
166
+ <Button label="Cancel" onPress={() => setSheet(null)} />
167
+ <Button label={sessions.length === 2 ? "Archive both" : `Archive ${sessions.length}`} variant="danger" onPress={() => void confirm(false)} />
168
+ </View>
169
+ </Dialog>
170
+ ) : sheet === "dirty" ? (
171
+ <ArchiveSheet
172
+ title={leaving.length === 1 ? `Archive "${leaving[0]}"?` : sessions.length > 1 ? `Archive the sessions on #${item.number}?` : `Archive the session on #${item.number}?`}
173
+ unsaved={unsaved.length ? unsaved : [readingOf(sessions[0])]}
174
+ onOpen={() => openSession(unsaved[0]?.agentId ?? sessions[0].id)}
175
+ onArchive={() => void confirm(true)}
176
+ onClose={() => setSheet(null)}
177
+ />
161
178
  ) : null
162
179
  }
163
180
  />
@@ -166,32 +183,81 @@ function WrapRow({ item, first, busy, login, fixture, openAgent: openSession, on
166
183
 
167
184
  // What a session in Wrap up's multi sheet says about its worktree [ATT-22].
168
185
  function sessionStateText(session: AgentSummary): string {
169
- const state = sessionCleanliness(session);
170
- if (state === "clean") return "idle · nothing unsaved";
171
- if (state === "dirty") return `idle · ${unsavedText(session)}`;
172
- return "idle · couldn't check for unsaved changes";
186
+ const unsaved = sessionUnsaved(session);
187
+ if (!unsaved) return "idle · nothing unsaved";
188
+ return sessionCleanliness(session) === "unknown" ? "idle · couldn't check for unsaved changes" : `idle · ${unsavedWords(unsaved)}`;
173
189
  }
174
190
 
175
- function dirtyFallback(session: AgentSummary | undefined): UnsavedSession {
176
- const workspace = session?.workspace;
177
- return session
178
- ? {
179
- agentId: session.id,
180
- title: session.title,
181
- ...(workspace?.branch ? { branch: workspace.branch } : {}),
182
- ...(workspace?.dirtyFiles ? { files: workspace.dirtyFiles } : {}),
183
- ...(workspace?.ahead ? { commits: workspace.ahead } : {}),
184
- ...(sessionCleanliness(session) === "unknown" ? { unknown: true as const } : {}),
185
- }
186
- : { agentId: "", title: null, unknown: true };
191
+ // What the confirm sheet names for a session the server hasn't checked: Paseo's reading of it.
192
+ const readingOf = (session: AgentSummary | undefined): UnsavedSession =>
193
+ session ? (sessionUnsaved(session) ?? { agentId: session.id, title: session.title }) : { agentId: "", title: null, unknown: true };
194
+
195
+ // The confirm sheet, shaped like Paseo's "Archive workspace" one: what each session's worktree would lose, in Paseo's
196
+ // words, then the terminals archiving closes; Open session to look first, or Archive [ATT-22].
197
+ function ArchiveSheet({ title, unsaved, onOpen, onArchive, onClose }: { title: string; unsaved: UnsavedSession[]; onOpen?: () => void; onArchive: () => void; onClose: () => void }) {
198
+ const styles = useStyles();
199
+ return (
200
+ <Dialog title={title} onClose={onClose}>
201
+ {unsaved.map((info) => (
202
+ <View key={info.agentId} style={{ gap: 2 }}>
203
+ {unsaved.length > 1 || info.title ? <Text style={styles.text}>{info.title ?? "Session"}</Text> : null}
204
+ {sheetLines(info).map((line) => (
205
+ <Text key={line} style={{ color: line.startsWith("Closes") ? styles.c.foregroundMuted : styles.c.statusWarning, fontSize: 13 }}>
206
+ {line}
207
+ </Text>
208
+ ))}
209
+ </View>
210
+ ))}
211
+ <View style={[styles.row, { justifyContent: "flex-end" }]}>
212
+ {onOpen ? <Button label="Open session" icon="agent" variant="calm" onPress={onOpen} /> : <Button label="Cancel" onPress={onClose} />}
213
+ <Button label="Archive" variant="danger" onPress={onArchive} />
214
+ </View>
215
+ </Dialog>
216
+ );
187
217
  }
188
218
 
189
- // "2 uncommitted files and 1 unpushed commit on branch", from the archive check's git counts [ATT-22].
190
- function unsavedTextFrom(info: UnsavedSession): string {
191
- if (info.unknown) return "changes Paseo couldn't check";
192
- const parts: string[] = [];
193
- if (info.files) parts.push(`${info.files} uncommitted file${info.files === 1 ? "" : "s"}`);
194
- if (info.commits) parts.push(`${info.commits} unpushed commit${info.commits === 1 ? "" : "s"}`);
195
- const what = parts.join(" and ") || "unsaved changes";
196
- return info.branch ? `${what} on ${info.branch}` : what;
219
+ // A row whose sessions are archived but whose worktree stayed, saying why, until the worktree goes or I dismiss it [ATT-22].
220
+ // Its button fits the reason: open the session that kept it, archive the worktree a terminal kept, or try Paseo again.
221
+ function KeptWorktreeRow({
222
+ row,
223
+ first,
224
+ busy,
225
+ login,
226
+ openSession,
227
+ onArchive,
228
+ onDismiss,
229
+ }: {
230
+ row: KeptRow;
231
+ first: boolean;
232
+ busy: boolean;
233
+ login: string | null;
234
+ openSession: (agentId: string) => void;
235
+ onArchive: KeptProps["onArchiveWorktree"];
236
+ onDismiss: (row: KeptRow) => void;
237
+ }) {
238
+ const [sheet, setSheet] = useState<{ unsaved: UnsavedSession[]; terminals: string[] } | null>(null);
239
+ const archive = async (confirm: boolean) => {
240
+ const outcome = await onArchive(row, confirm, confirm ? (sheet?.terminals ?? []) : []);
241
+ if (outcome && !outcome.ok && outcome.reason === "unsaved") return setSheet({ unsaved: outcome.sessions, terminals: outcome.terminals });
242
+ setSheet(null);
243
+ };
244
+ const primary =
245
+ row.reason === "session" && row.agentId
246
+ ? { label: "Open session", icon: "agent" as const, onPress: () => openSession(row.agentId!) }
247
+ : { label: row.reason === "refused" ? "Try again" : "Archive worktree", icon: "archive" as const, onPress: () => void archive(false) };
248
+ return (
249
+ <CardRow
250
+ first={first}
251
+ mark={{ icon: "archive", tone: "neutral" }}
252
+ title={row.title}
253
+ meta={{ place: { repo: row.repo, number: row.number, login }, when: keptText(row), signals: [] }}
254
+ onOpen={primary.onPress}
255
+ busy={busy}
256
+ primary={{ ...primary, accessibilityLabel: `${primary.label}: ${row.name}` }}
257
+ secondary={[{ label: "Dismiss", icon: "close", accessibilityLabel: `Dismiss: keep ${row.name}`, onPress: () => onDismiss(row) }]}
258
+ overlay={
259
+ sheet ? <ArchiveSheet title={`Archive "${row.name}"?`} unsaved={sheet.unsaved} onArchive={() => void archive(true)} onClose={() => setSheet(null)} /> : null
260
+ }
261
+ />
262
+ );
197
263
  }