paseo-office 0.2.6 → 0.2.8

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.
@@ -0,0 +1,195 @@
1
+ import { useCallback, useMemo, useState } from "react";
2
+ import { StyleSheet, Text, View } from "react-native";
3
+ import { Icon, TextInput } from "@getpaseo/plugin/client/ui";
4
+ import {
5
+ HINT_MAX,
6
+ checksNote,
7
+ clashNote,
8
+ portNote,
9
+ type Alert,
10
+ type AlertKind,
11
+ } from "../shared/alerts.js";
12
+ import type { Machine } from "../shared/contracts.js";
13
+ import { ActionButton } from "./action-button.js";
14
+ import { OfficeModal as Modal } from "./office-modal.js";
15
+ import type { OfficeStyles } from "./styles.js";
16
+ import type { AgentActions } from "./use-agent-actions.js";
17
+
18
+ const layout = StyleSheet.create({
19
+ row: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 },
20
+ field: { flex: 1, minWidth: 160 },
21
+ });
22
+
23
+ const STEER = { activeTurnBehavior: "steer" } as const;
24
+
25
+ const ABOUT: Readonly<Record<AlertKind, string>> = {
26
+ loop: "Stop ends its turn. A hint is sent into the turn, so the agent reads it without starting over.",
27
+ refused:
28
+ "The provider's auto mode refused this call. The agent was told and goes on; nothing is waiting for you.",
29
+ clash: "Tell both sends each a line about the other, into its turn.",
30
+ port: "Tell the agent sends it a line to use another port, into its turn.",
31
+ checks: "Fix it sends the failing checks to an agent of this workspace that is resting.",
32
+ };
33
+
34
+ export interface AlertCardProps {
35
+ /** The alert to show; null closes the card. */
36
+ alert: Alert | null;
37
+ /** The office's name for an agent, for a line sent to another one. */
38
+ nameOf(agentId: string): string;
39
+ /** The host's readings: who holds a port. */
40
+ machine: Machine | null;
41
+ actions: AgentActions;
42
+ styles: OfficeStyles;
43
+ onClose(): void;
44
+ onDismiss(): Promise<void>;
45
+ }
46
+
47
+ interface ActProps extends Omit<AlertCardProps, "alert" | "onClose"> {
48
+ alert: Alert;
49
+ }
50
+
51
+ /** The loop's: stop the turn, or send a hint into it. */
52
+ function LoopActions({ alert, actions, styles, onDismiss }: ActProps) {
53
+ const [hint, setHint] = useState("");
54
+ const agentId = alert.agentId ?? "";
55
+ const { cancel } = actions;
56
+ const stop = useCallback(async () => {
57
+ await cancel?.(agentId);
58
+ await onDismiss();
59
+ }, [cancel, agentId, onDismiss]);
60
+ const send = useCallback(async () => {
61
+ await actions.send(agentId, hint.trim().slice(0, HINT_MAX), STEER);
62
+ await onDismiss();
63
+ }, [actions, agentId, hint, onDismiss]);
64
+ const field = useMemo(() => [styles.fieldInput, layout.field], [styles]);
65
+ return (
66
+ <>
67
+ <View style={layout.row}>
68
+ <TextInput
69
+ accessibilityLabel="Hint for the agent"
70
+ value={hint}
71
+ onChangeText={setHint}
72
+ placeholder="What it should try instead"
73
+ maxLength={HINT_MAX}
74
+ style={field}
75
+ />
76
+ <ActionButton
77
+ label="Send a hint"
78
+ pendingLabel="Sending..."
79
+ onPress={send}
80
+ disabled={hint.trim() === ""}
81
+ styles={styles}
82
+ primary
83
+ />
84
+ </View>
85
+ {cancel ? (
86
+ <ActionButton label="Stop" pendingLabel="Stopping..." onPress={stop} styles={styles} />
87
+ ) : null}
88
+ </>
89
+ );
90
+ }
91
+
92
+ /** What is sent to whom for an alert that is answered with one line; null when there is nobody to send to. */
93
+ function linesOf({
94
+ alert,
95
+ nameOf,
96
+ machine,
97
+ }: ActProps): { label: string; to: [string, string][] } | null {
98
+ const { agentId, otherAgentId } = alert;
99
+ if (agentId === undefined) return null;
100
+ if (alert.kind === "clash" && otherAgentId !== undefined) {
101
+ // (the alert's title names the file only when the host may name files)
102
+ const file = /are in (.+)$/.exec(alert.title)?.[1] ?? "the same file";
103
+ return {
104
+ label: "Tell both",
105
+ to: [
106
+ [agentId, clashNote(file, nameOf(otherAgentId))],
107
+ [otherAgentId, clashNote(file, nameOf(agentId))],
108
+ ],
109
+ };
110
+ }
111
+ if (alert.kind === "port" && alert.port !== undefined) {
112
+ const { port } = alert;
113
+ const holder = machine?.agents.find(
114
+ (held) => held.agentId !== agentId && held.ports.includes(port),
115
+ );
116
+ const name = holder === undefined ? null : nameOf(holder.agentId);
117
+ return { label: "Tell the agent", to: [[agentId, portNote(port, name)]] };
118
+ }
119
+ if (alert.kind === "checks") {
120
+ return { label: "Fix it", to: [[agentId, checksNote(alert.detail)]] };
121
+ }
122
+ return null;
123
+ }
124
+
125
+ function LineAction(props: ActProps) {
126
+ const { alert, actions, styles, onDismiss } = props;
127
+ const lines = linesOf(props);
128
+ const send = useCallback(async () => {
129
+ if (lines === null) return;
130
+ // Failing checks go to a resting agent as its prompt; the rest join a running turn.
131
+ const options = alert.kind === "checks" ? undefined : STEER;
132
+ await Promise.all(lines.to.map(([agentId, text]) => actions.send(agentId, text, options)));
133
+ await onDismiss();
134
+ }, [lines, alert.kind, actions, onDismiss]);
135
+ if (alert.kind === "refused") return null;
136
+ if (lines === null) {
137
+ return <Text style={styles.host.note}>No agent of this workspace is resting now.</Text>;
138
+ }
139
+ return (
140
+ <ActionButton
141
+ label={lines.label}
142
+ pendingLabel="Sending..."
143
+ onPress={send}
144
+ styles={styles}
145
+ primary
146
+ />
147
+ );
148
+ }
149
+
150
+ /** One thing the office noticed, with what can be done about it. */
151
+ export function AlertCard({ alert, onClose, ...rest }: AlertCardProps) {
152
+ const { styles, onDismiss } = rest;
153
+ const change = useCallback(
154
+ (next: boolean) => {
155
+ if (!next) onClose();
156
+ },
157
+ [onClose],
158
+ );
159
+ const icon = useMemo(
160
+ () => <Icon name="TriangleAlert" size={18} color={String(styles.host.label.color)} />,
161
+ [styles],
162
+ );
163
+ return (
164
+ <Modal icon={icon} title="Noticed" open={alert !== null} onOpenChange={change}>
165
+ <Modal.Content>
166
+ {alert !== null && (
167
+ <View style={styles.host.body}>
168
+ <View style={styles.host.group}>
169
+ <Text accessibilityRole="header" style={styles.host.title}>
170
+ {alert.title}
171
+ </Text>
172
+ {alert.detail !== "" && (
173
+ <Text selectable style={styles.rowMeta}>
174
+ {alert.detail}
175
+ </Text>
176
+ )}
177
+ <Text style={styles.host.note}>{ABOUT[alert.kind]}</Text>
178
+ </View>
179
+ {alert.kind === "loop" ? (
180
+ <LoopActions alert={alert} {...rest} />
181
+ ) : (
182
+ <LineAction alert={alert} {...rest} />
183
+ )}
184
+ <ActionButton
185
+ label="Dismiss"
186
+ pendingLabel="Dismissing..."
187
+ onPress={onDismiss}
188
+ styles={styles}
189
+ />
190
+ </View>
191
+ )}
192
+ </Modal.Content>
193
+ </Modal>
194
+ );
195
+ }
@@ -8,14 +8,17 @@ import { SettingField } from "./setting-field.js";
8
8
  import { WeatherFields, type WeatherSetting } from "./weather-settings.js";
9
9
  import type { IncidentsState, WakeState } from "../shared/contracts.js";
10
10
  import {
11
+ CACHE_CLOCKS,
11
12
  officeHostSettings,
12
13
  STICKY_NOTES_MAX,
14
+ type CacheClock,
13
15
  STICKY_NOTE_MAX,
14
16
  type FloorPlanChoice,
15
17
  } from "../shared/settings.js";
16
18
  import { failureText } from "./action-button.js";
17
19
  import { wakeSummary } from "./board-text.js";
18
20
  import { FLOOR_PLAN_LABEL, FloorPlanRow } from "./floor-plan-row.js";
21
+ import { SegmentPill } from "./segment-pill.js";
19
22
  import { LabeledSwitch } from "./labeled-switch.js";
20
23
  import { NOTES_DAYS_LABEL, NotesDays } from "./notes-days.js";
21
24
  import { NOTES_MODE_LABEL, NotesModeRow } from "./notes-mode-row.js";
@@ -34,6 +37,8 @@ type HostSetting =
34
37
  | "Agent tools"
35
38
  | "Streamer mode"
36
39
  | "History vault"
40
+ | "Pinned notes"
41
+ | "Cache clock"
37
42
  | "Sticky notes"
38
43
  | "Notes folder"
39
44
  | "Time zone"
@@ -257,6 +262,7 @@ export function HostSwitches({
257
262
  saveProblem={saveProblem}
258
263
  styles={styles}
259
264
  />
265
+ <PinnedNotes values={stored} change={change} saveProblem={saveProblem} styles={styles} />
260
266
  <Text style={styles.sheetLabel}>Stand-up schedule</Text>
261
267
  <View style={styles.headerFields}>
262
268
  <SettingField
@@ -432,6 +438,12 @@ function TrackerFields({ values, incidents, change, saveProblem, styles }: Track
432
438
  );
433
439
  }
434
440
 
441
+ const CACHE_CLOCK_NAMES: Readonly<Record<CacheClock, string>> = {
442
+ off: "No cup",
443
+ "5m": "5 minutes",
444
+ "1h": "1 hour",
445
+ };
446
+
435
447
  /** The floor's own: what bubbles may name, and the owner's notes on the whiteboard. */
436
448
  function FloorSettings({
437
449
  values: stored,
@@ -453,6 +465,11 @@ function FloorSettings({
453
465
  [change],
454
466
  );
455
467
  const vaultProblem = saveProblem("History vault");
468
+ const saveCache = useCallback(
469
+ (next: CacheClock) => void change("Cache clock", { cacheClock: next }),
470
+ [change],
471
+ );
472
+ const cacheProblem = saveProblem("Cache clock");
456
473
  return (
457
474
  <View style={settingsLayout.block}>
458
475
  {stored && (
@@ -490,6 +507,36 @@ function FloorSettings({
490
507
  {vaultProblem}
491
508
  </Text>
492
509
  )}
510
+ <View style={styles.headerField}>
511
+ <Text style={styles.sheetLabel}>Cache clock</Text>
512
+ <View
513
+ role="group"
514
+ aria-label="Cache clock"
515
+ style={stored ? styles.segments : styles.segmentsDisabled}
516
+ >
517
+ {CACHE_CLOCKS.map((value) => (
518
+ <SegmentPill
519
+ key={value}
520
+ value={value}
521
+ name={CACHE_CLOCK_NAMES[value]}
522
+ on={stored?.cacheClock === value}
523
+ disabled={stored === null}
524
+ onPress={saveCache}
525
+ styles={styles}
526
+ />
527
+ ))}
528
+ </View>
529
+ <Text style={styles.fieldHint}>
530
+ The cup on a resting desk of the 3D floor steams while the session&apos;s prompt cache is
531
+ taken to be warm: this long after its last turn. An estimate; a subscription keeps the
532
+ cache about an hour, an API key five minutes.
533
+ </Text>
534
+ {cacheProblem && (
535
+ <Text accessibilityRole="alert" style={styles.actionError}>
536
+ {cacheProblem}
537
+ </Text>
538
+ )}
539
+ </View>
493
540
  <SettingField
494
541
  label="Sticky notes"
495
542
  hint={`Your notes on the 3D whiteboard, with ; between them. Up to ${STICKY_NOTES_MAX}, ${STICKY_NOTE_MAX} characters each.`}
@@ -502,6 +549,30 @@ function FloorSettings({
502
549
  );
503
550
  }
504
551
 
552
+ function PinnedNotes({
553
+ values: stored,
554
+ change,
555
+ saveProblem,
556
+ styles,
557
+ }: Omit<TrackerFieldsProps, "incidents">) {
558
+ const save = useCallback(
559
+ (next: string) => change("Pinned notes", { pinnedNotes: next }),
560
+ [change],
561
+ );
562
+ return (
563
+ <View style={styles.headerFields}>
564
+ <SettingField
565
+ label="Pinned notes"
566
+ hint="Said again to an agent whose conversation is compacted during a turn, so a rule you gave it is not lost. Empty says nothing."
567
+ value={stored?.pinnedNotes ?? null}
568
+ onSave={save}
569
+ problem={saveProblem("Pinned notes")}
570
+ styles={styles}
571
+ />
572
+ </View>
573
+ );
574
+ }
575
+
505
576
  function ArchiveSetting({
506
577
  values: stored,
507
578
  change,
@@ -0,0 +1,97 @@
1
+ import { useCallback, useMemo, useState } from "react";
2
+ import { Text, View } from "react-native";
3
+ import { useRpc } from "@getpaseo/plugin/client";
4
+ import { forgottenRpc, type OfficeAgent } from "../shared/contracts.js";
5
+ import {
6
+ coordinatorModels,
7
+ forgottenText,
8
+ subModelsText,
9
+ type Forgotten,
10
+ } from "../shared/forgotten.js";
11
+ import { ActionButton } from "./action-button.js";
12
+ import type { OfficeStyles } from "./styles.js";
13
+
14
+ /**
15
+ * Checkouts with work nobody finished: changed files, commits on no remote, a stash. Read when
16
+ * asked, since it runs git in every workspace's folder.
17
+ */
18
+ export function ForgottenWork({ styles }: { styles: OfficeStyles }) {
19
+ const read = useRpc(forgottenRpc);
20
+ const [found, setFound] = useState<readonly Forgotten[] | null>(null);
21
+ const check = useCallback(async () => {
22
+ const answer = await read({});
23
+ setFound(answer.items);
24
+ }, [read]);
25
+ return (
26
+ <View style={styles.host.group}>
27
+ <View style={styles.host.groupHead}>
28
+ <Text accessibilityRole="header" style={styles.host.title}>
29
+ Forgotten work
30
+ </Text>
31
+ <ActionButton
32
+ label={found === null ? "Check" : "Check again"}
33
+ pendingLabel="Checking..."
34
+ name="Check for forgotten work"
35
+ onPress={check}
36
+ styles={styles}
37
+ />
38
+ </View>
39
+ {found === null && (
40
+ <Text style={styles.host.note}>
41
+ Looks in each workspace&apos;s folder, and its repository&apos;s other worktrees, for
42
+ files not committed, commits no remote has, and stashes.
43
+ </Text>
44
+ )}
45
+ {found !== null && found.length === 0 && (
46
+ <Text style={styles.host.empty}>Every checkout is committed and pushed.</Text>
47
+ )}
48
+ {found?.map((item) => (
49
+ <View
50
+ key={`${item.workspaceId ?? ""}:${item.name}`}
51
+ accessible
52
+ accessibilityRole="text"
53
+ accessibilityLabel={`${item.name}: ${forgottenText(item)}`}
54
+ >
55
+ <Text style={styles.host.name}>{item.name}</Text>
56
+ <Text style={styles.host.note}>
57
+ {forgottenText(item)}
58
+ {item.workspaceId === null ? " (a worktree no workspace has)" : ""}
59
+ </Text>
60
+ </View>
61
+ ))}
62
+ </View>
63
+ );
64
+ }
65
+
66
+ /** Each agent that has sub-agents, with its model and the models they run on; nothing while none has. */
67
+ export function SubagentModels({
68
+ agents,
69
+ styles,
70
+ }: {
71
+ agents: readonly OfficeAgent[];
72
+ styles: OfficeStyles;
73
+ }) {
74
+ const coordinators = useMemo(() => coordinatorModels(agents), [agents]);
75
+ if (coordinators.length === 0) return null;
76
+ return (
77
+ <View style={styles.host.group}>
78
+ <Text accessibilityRole="header" style={styles.host.title}>
79
+ Models
80
+ </Text>
81
+ {coordinators.map((lead) => {
82
+ const text = `${lead.model ?? "an unnamed model"}; sub-agents: ${subModelsText(lead.subs)}`;
83
+ return (
84
+ <View
85
+ key={lead.id}
86
+ accessible
87
+ accessibilityRole="text"
88
+ accessibilityLabel={`${lead.name}: ${text}`}
89
+ >
90
+ <Text style={styles.host.name}>{lead.name}</Text>
91
+ <Text style={styles.host.note}>{text}</Text>
92
+ </View>
93
+ );
94
+ })}
95
+ </View>
96
+ );
97
+ }
@@ -2,7 +2,8 @@ import { useCallback, useMemo, useState } from "react";
2
2
  import { Text, View, type ViewStyle } from "react-native";
3
3
  import { OfficeModal as Modal } from "./office-modal.js";
4
4
  import { Icon } from "@getpaseo/plugin/client/ui";
5
- import type { Machine, MachineAgent, OfficeWorkspace } from "../shared/contracts.js";
5
+ import type { Machine, MachineAgent, OfficeAgent, OfficeWorkspace } from "../shared/contracts.js";
6
+ import { ForgottenWork, SubagentModels } from "./host-work.js";
6
7
  import { HostViews, NO_SSH, type SshDiscovery } from "./ssh-hosts.js";
7
8
  import { LocalHostDetails } from "./host-details.js";
8
9
  import { ActionButton } from "./action-button.js";
@@ -102,6 +103,10 @@ function PlanLimits({
102
103
  ))}
103
104
  </View>
104
105
  ))}
106
+ <Text style={styles.host.note}>
107
+ To switch accounts, use the account-switcher plugin. The office reads the limits and handles
108
+ no sign-in.
109
+ </Text>
105
110
  </View>
106
111
  );
107
112
  }
@@ -234,6 +239,8 @@ function AgentGroup({ title, agents, now, actionFor, cleanUp, styles, empty }: A
234
239
 
235
240
  interface MachineBodyProps {
236
241
  workspaces?: readonly OfficeWorkspace[];
242
+ /** The office's agents, for the models of those that have sub-agents. */
243
+ agents?: readonly OfficeAgent[];
237
244
  machine: Machine;
238
245
  cleanUp(agentIds: readonly string[]): Promise<void>;
239
246
  styles: OfficeStyles;
@@ -247,7 +254,15 @@ const CLOSE = { label: "Close runtime", pendingLabel: "Closing...", primary: fal
247
254
 
248
255
  const NO_WORKSPACES: readonly OfficeWorkspace[] = [];
249
256
 
250
- function MachineBody({ machine, cleanUp, styles, workspaces = NO_WORKSPACES }: MachineBodyProps) {
257
+ const NO_AGENTS: readonly OfficeAgent[] = [];
258
+
259
+ function MachineBody({
260
+ machine,
261
+ cleanUp,
262
+ styles,
263
+ workspaces = NO_WORKSPACES,
264
+ agents = NO_AGENTS,
265
+ }: MachineBodyProps) {
251
266
  const usage = usePlanUsageValue();
252
267
  const [expanded, setExpanded] = useState(false);
253
268
  const toggle = useCallback(() => setExpanded((value) => !value), []);
@@ -301,6 +316,8 @@ function MachineBody({ machine, cleanUp, styles, workspaces = NO_WORKSPACES }: M
301
316
  </View>
302
317
  {expanded && <LocalHostDetails machine={machine} workspaces={workspaces} styles={styles} />}
303
318
  <PlanLimits usage={usage} now={now} styles={styles} />
319
+ <SubagentModels agents={agents} styles={styles} />
320
+ <ForgottenWork styles={styles} />
304
321
  {left.length > 0 ? (
305
322
  <View style={styles.host.group}>
306
323
  <AgentGroup
@@ -346,6 +363,7 @@ function MachineBody({ machine, cleanUp, styles, workspaces = NO_WORKSPACES }: M
346
363
 
347
364
  export interface MachineCardProps {
348
365
  workspaces?: readonly OfficeWorkspace[];
366
+ agents?: readonly OfficeAgent[];
349
367
  /** Empty on hosts without local readings. */
350
368
  machine: Machine | null;
351
369
  ssh?: SshDiscovery;
@@ -360,6 +378,7 @@ export function MachineCard({
360
378
  machine,
361
379
  ssh = NO_SSH,
362
380
  workspaces,
381
+ agents,
363
382
  open,
364
383
  cleanUp,
365
384
  styles,
@@ -384,6 +403,7 @@ export function MachineCard({
384
403
  {machine ? (
385
404
  <MachineBody
386
405
  workspaces={workspaces}
406
+ agents={agents}
387
407
  machine={machine}
388
408
  cleanUp={cleanUp}
389
409
  styles={styles}
@@ -63,6 +63,8 @@ import { JanitorCard } from "./janitor-card.js";
63
63
  import { TimelineCard } from "./timeline-card.js";
64
64
  import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
65
65
  import { VaultCard } from "./vault-card.js";
66
+ import { AlertCard } from "./alert-card.js";
67
+ import { useAlerts } from "./use-alerts.js";
66
68
  import { useSshServers } from "./ssh-hosts.js";
67
69
  import { MachineCard } from "./machine-card.js";
68
70
  import { hostNote, memoryPercent, namedMachine, type HostNote } from "../shared/machine-text.js";
@@ -1946,6 +1948,7 @@ export function OfficeSurface(
1946
1948
  const planUsage = usePlanUsage(live);
1947
1949
  const timeline = useTimelineCard(live);
1948
1950
  const history = useTimelineCard(live);
1951
+ const alerts = useAlerts(live);
1949
1952
  const board = useBoardSheet(model, live);
1950
1953
  const dutyCard = useCardOpening(live);
1951
1954
  // Until the host sends its duty list (an older host has none) nothing offers the duty board.
@@ -2075,6 +2078,7 @@ export function OfficeSurface(
2075
2078
  () =>
2076
2079
  [
2077
2080
  incidentsStripEntry,
2081
+ ...alerts.cards,
2078
2082
  settingsStripEntry,
2079
2083
  weatherStripEntry,
2080
2084
  hostEntry,
@@ -2086,6 +2090,7 @@ export function OfficeSurface(
2086
2090
  ].filter((card) => card !== null),
2087
2091
  [
2088
2092
  incidentsStripEntry,
2093
+ alerts.cards,
2089
2094
  settingsStripEntry,
2090
2095
  weatherStripEntry,
2091
2096
  hostEntry,
@@ -2288,6 +2293,7 @@ export function OfficeSurface(
2288
2293
  />
2289
2294
  <MachineCard
2290
2295
  workspaces={office.state.workspaces}
2296
+ agents={office.state.agents}
2291
2297
  ssh={ssh}
2292
2298
  machine={machine}
2293
2299
  open={machineOpen}
@@ -2297,6 +2303,15 @@ export function OfficeSurface(
2297
2303
  />
2298
2304
  <TimelineCard open={timeline.open} styles={styles} onClose={timeline.close} />
2299
2305
  <VaultCard open={history.open} styles={styles} onClose={history.close} />
2306
+ <AlertCard
2307
+ alert={alerts.open}
2308
+ nameOf={name}
2309
+ machine={machine}
2310
+ actions={actions}
2311
+ styles={styles}
2312
+ onClose={alerts.close}
2313
+ onDismiss={alerts.dismiss}
2314
+ />
2300
2315
  <JanitorCard
2301
2316
  rows={contexts}
2302
2317
  open={janitorOpen && live}
@@ -9,7 +9,9 @@ import {
9
9
  TIMELINE_RANGES,
10
10
  doingAt,
11
11
  durationText,
12
+ planEaters,
12
13
  weekRecap,
14
+ type PlanEater,
13
15
  type ReplaySpeed,
14
16
  type Timeline,
15
17
  type TimelineLane,
@@ -146,8 +148,14 @@ function Figure({ label, value, styles }: { label: string; value: string; styles
146
148
  );
147
149
  }
148
150
 
151
+ function eaterText(eater: PlanEater): string {
152
+ const worked = `${durationText(eater.workMs)} at work`;
153
+ return eater.costUsd === null ? worked : `$${eater.costUsd.toFixed(2)}, ${worked}`;
154
+ }
155
+
149
156
  function Week({ timeline, styles }: { timeline: Timeline; styles: OfficeStyles }) {
150
157
  const recap = useMemo(() => weekRecap(timeline), [timeline]);
158
+ const eaters = useMemo(() => planEaters(timeline), [timeline]);
151
159
  const most = Math.max(1, ...recap.days.map((day) => day.workMs));
152
160
  const bars = useMemo(
153
161
  () =>
@@ -204,6 +212,27 @@ function Week({ timeline, styles }: { timeline: Timeline; styles: OfficeStyles }
204
212
  <Text style={styles.host.note}>
205
213
  Counted from what the office saw while it was open, in the 24 hours each bar ends.
206
214
  </Text>
215
+ <View style={styles.host.group}>
216
+ <Text accessibilityRole="header" style={styles.host.title}>
217
+ What eats your plan
218
+ </Text>
219
+ {eaters.map((eater) => (
220
+ <View
221
+ key={eater.id}
222
+ accessible
223
+ accessibilityRole="text"
224
+ accessibilityLabel={`${eater.name}: ${eaterText(eater)}`}
225
+ style={layout.laneHead}
226
+ >
227
+ <Text style={styles.host.name} numberOfLines={1}>
228
+ {eater.name}
229
+ </Text>
230
+ <Text style={styles.host.note}>
231
+ {eater.team} · {eaterText(eater)}
232
+ </Text>
233
+ </View>
234
+ ))}
235
+ </View>
207
236
  </View>
208
237
  );
209
238
  }
@@ -0,0 +1,71 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { useRpc } from "@getpaseo/plugin/client";
3
+ import type { Alert } from "../shared/alerts.js";
4
+ import { alertDismissRpc, alertsRpc } from "../shared/contracts.js";
5
+ import type { StripCard } from "./attention-strip.js";
6
+
7
+ const NO_ALERTS: readonly Alert[] = [];
8
+ /** The office's own reads are 5 s apart: asking every other one is soon enough. */
9
+ const EVERY_MS = 10_000;
10
+
11
+ export interface AlertsState {
12
+ /** A card of the Attention strip for each alert, newest first. */
13
+ cards: StripCard[];
14
+ /** The alert whose card is open; null when none is, and once it is gone. */
15
+ open: Alert | null;
16
+ close(): void;
17
+ /** Dismisses the open alert and closes its card. */
18
+ dismiss(): Promise<void>;
19
+ }
20
+
21
+ /** What the office noticed, asked for while `live`, as cards that open one alert at a time. */
22
+ export function useAlerts(live: boolean): AlertsState {
23
+ const ask = useRpc(alertsRpc);
24
+ const drop = useRpc(alertDismissRpc);
25
+ // Kept in a ref: the poll restarts when the office goes live, not when the call's identity changes.
26
+ const asking = useRef(ask);
27
+ asking.current = ask;
28
+ const [alerts, setAlerts] = useState<readonly Alert[]>(NO_ALERTS);
29
+ const [openId, setOpenId] = useState<string | null>(null);
30
+ useEffect(() => {
31
+ if (!live) {
32
+ setAlerts(NO_ALERTS);
33
+ return undefined;
34
+ }
35
+ let ended = false;
36
+ const read = async () => {
37
+ try {
38
+ const answer = await asking.current({});
39
+ if (!ended) setAlerts(answer.alerts);
40
+ } catch {
41
+ // (the host went away: the next reading says)
42
+ }
43
+ };
44
+ void read();
45
+ const timer = setInterval(() => void read(), EVERY_MS);
46
+ return () => {
47
+ ended = true;
48
+ clearInterval(timer);
49
+ };
50
+ }, [live]);
51
+ const cards = useMemo(
52
+ () =>
53
+ alerts.map(
54
+ (alert): StripCard => ({
55
+ title: alert.title,
56
+ note: { text: alert.detail || "Open to act on it", tone: "warning" },
57
+ onOpen: () => setOpenId(alert.id),
58
+ }),
59
+ ),
60
+ [alerts],
61
+ );
62
+ const open = useMemo(() => alerts.find((alert) => alert.id === openId) ?? null, [alerts, openId]);
63
+ const close = useCallback(() => setOpenId(null), []);
64
+ const dismiss = useCallback(async () => {
65
+ if (openId === null) return;
66
+ const answer = await drop({ id: openId });
67
+ setAlerts(answer.alerts);
68
+ setOpenId(null);
69
+ }, [drop, openId]);
70
+ return { cards, open, close, dismiss };
71
+ }