paseo-office 0.0.0-stage → 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.
Files changed (198) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +144 -2
  3. package/client/action-button.tsx +124 -0
  4. package/client/activity-feed-text.ts +84 -0
  5. package/client/activity-feed.ts +339 -0
  6. package/client/activity-panel.tsx +306 -0
  7. package/client/agent-card.tsx +230 -0
  8. package/client/agent-picker-text.ts +97 -0
  9. package/client/agent-picker.tsx +160 -0
  10. package/client/app-locale.ts +14 -0
  11. package/client/ask-text.ts +75 -0
  12. package/client/attention-strip.tsx +194 -0
  13. package/client/beside.ts +42 -0
  14. package/client/board-sheet.tsx +419 -0
  15. package/client/board-text.ts +95 -0
  16. package/client/brand.ts +29 -0
  17. package/client/chat-acts.ts +24 -0
  18. package/client/chat-panel.tsx +832 -0
  19. package/client/chat-seen.ts +63 -0
  20. package/client/chat-text.ts +230 -0
  21. package/client/choice-pills.tsx +75 -0
  22. package/client/column-model.ts +68 -0
  23. package/client/column-sheet.tsx +157 -0
  24. package/client/context-text.ts +130 -0
  25. package/client/conversation-model.ts +149 -0
  26. package/client/floor-plan-row.tsx +84 -0
  27. package/client/focus-request.ts +6 -0
  28. package/client/follow-end.ts +28 -0
  29. package/client/fullscreen-header.tsx +123 -0
  30. package/client/host-switches.tsx +357 -0
  31. package/client/incidents-card.tsx +125 -0
  32. package/client/incidents-text.ts +81 -0
  33. package/client/janitor-card.tsx +165 -0
  34. package/client/labeled-switch.tsx +49 -0
  35. package/client/language-switch.tsx +57 -0
  36. package/client/library-card.tsx +327 -0
  37. package/client/library-text.ts +166 -0
  38. package/client/list-text.ts +177 -0
  39. package/client/lobby-board.tsx +355 -0
  40. package/client/luminance.ts +38 -0
  41. package/client/machine-card.tsx +220 -0
  42. package/client/new-agent-form.tsx +261 -0
  43. package/client/new-agent-model.ts +165 -0
  44. package/client/notes-card.tsx +320 -0
  45. package/client/notes-days.tsx +94 -0
  46. package/client/notes-text.ts +153 -0
  47. package/client/office-column.tsx +448 -0
  48. package/client/office-link.ts +47 -0
  49. package/client/office-settings.tsx +68 -0
  50. package/client/office-state.ts +78 -0
  51. package/client/office-surface.tsx +1786 -0
  52. package/client/permission-actions.tsx +123 -0
  53. package/client/pixel/actors.ts +294 -0
  54. package/client/pixel/art.ts +778 -0
  55. package/client/pixel/floor-plan.ts +282 -0
  56. package/client/pixel/pixel-office.tsx +1286 -0
  57. package/client/pixel/room.ts +62 -0
  58. package/client/pixel/sprite-view.tsx +71 -0
  59. package/client/pixel/sprite.ts +75 -0
  60. package/client/pixel/ticker.ts +40 -0
  61. package/client/qa-card.tsx +210 -0
  62. package/client/qa-text.ts +189 -0
  63. package/client/review-card.tsx +187 -0
  64. package/client/review-text.ts +207 -0
  65. package/client/room-board.tsx +65 -0
  66. package/client/segment-pill.tsx +58 -0
  67. package/client/session-pane.tsx +116 -0
  68. package/client/session-panel.tsx +377 -0
  69. package/client/session-styles.ts +140 -0
  70. package/client/session-text.ts +38 -0
  71. package/client/sessions-panel.tsx +289 -0
  72. package/client/sessions-text.ts +140 -0
  73. package/client/setting-field.tsx +71 -0
  74. package/client/settings-text.ts +25 -0
  75. package/client/standup-card.tsx +241 -0
  76. package/client/structure-view.tsx +425 -0
  77. package/client/styles.ts +1319 -0
  78. package/client/tab-reveal.ts +54 -0
  79. package/client/use-agent-actions.ts +35 -0
  80. package/client/use-board-actions.ts +57 -0
  81. package/client/use-column.ts +95 -0
  82. package/client/use-conversation.ts +246 -0
  83. package/client/use-device-switch.ts +79 -0
  84. package/client/use-incidents.ts +17 -0
  85. package/client/use-janitor.ts +19 -0
  86. package/client/use-library.ts +83 -0
  87. package/client/use-machine.ts +39 -0
  88. package/client/use-new-agent.ts +168 -0
  89. package/client/use-office.ts +66 -0
  90. package/client/use-qa.ts +25 -0
  91. package/client/use-reply-drafts.ts +34 -0
  92. package/client/use-reviews.ts +68 -0
  93. package/client/use-script-log.ts +27 -0
  94. package/client/use-sound.ts +8 -0
  95. package/client/use-standup.ts +46 -0
  96. package/client/use-street.ts +13 -0
  97. package/client/view-switch.tsx +83 -0
  98. package/client/weather-settings.tsx +84 -0
  99. package/client/weather-text.ts +31 -0
  100. package/client/web-env.web.ts +69 -0
  101. package/client/world/adapter.ts +421 -0
  102. package/client/world/rung-incidents.ts +25 -0
  103. package/client/world/script-frame-kit.ts +41 -0
  104. package/client/world/street-events.ts +18 -0
  105. package/client/world/use-floor-plan.ts +34 -0
  106. package/client/world/use-incident-alarm.ts +81 -0
  107. package/client/world/use-life.ts +40 -0
  108. package/client/world/use-scene-words.ts +76 -0
  109. package/client/world/use-street-kit.ts +28 -0
  110. package/client/world/use-world-feed.ts +174 -0
  111. package/client/world/words-loader.ts +35 -0
  112. package/client/world/world-api.ts +252 -0
  113. package/client/world/world-bridge-page.ts +46 -0
  114. package/client/world/world-bridge.ts +104 -0
  115. package/client/world/world-frame.web.ts +103 -0
  116. package/client/world/world-loader.ts +59 -0
  117. package/client/world/world-loading.tsx +11 -0
  118. package/client/world/world-view-native.tsx +204 -0
  119. package/client/world/world-view-shared.ts +170 -0
  120. package/client/world/world-view.tsx +276 -0
  121. package/docs/office.md +642 -0
  122. package/icon.png +0 -0
  123. package/index.client.tsx +59 -0
  124. package/index.server.ts +670 -0
  125. package/package.json +66 -4
  126. package/paseo-plugin.json +7 -0
  127. package/server/activity.ts +421 -0
  128. package/server/agent-tools.ts +153 -0
  129. package/server/board-service.ts +284 -0
  130. package/server/board-store.ts +115 -0
  131. package/server/chat-service.ts +446 -0
  132. package/server/chat-store.ts +122 -0
  133. package/server/directory.ts +392 -0
  134. package/server/errors.ts +3 -0
  135. package/server/fake-clock.ts +60 -0
  136. package/server/fake-schedules.ts +61 -0
  137. package/server/hub.ts +547 -0
  138. package/server/incidents-check.ts +213 -0
  139. package/server/incidents-http.ts +115 -0
  140. package/server/incidents-jira.ts +129 -0
  141. package/server/incidents-schedule.ts +87 -0
  142. package/server/incidents-sentry.ts +97 -0
  143. package/server/incidents-store.ts +122 -0
  144. package/server/janitor.ts +53 -0
  145. package/server/life-feed.ts +143 -0
  146. package/server/life-store.ts +93 -0
  147. package/server/lift-service.ts +75 -0
  148. package/server/live-ports.ts +214 -0
  149. package/server/local-schedules.ts +262 -0
  150. package/server/machine/cleanup.ts +98 -0
  151. package/server/machine/fake-proc.ts +87 -0
  152. package/server/machine/live-ports.ts +98 -0
  153. package/server/machine/machine.ts +79 -0
  154. package/server/machine/proc.ts +238 -0
  155. package/server/machine/reading.ts +70 -0
  156. package/server/machine/watch.ts +121 -0
  157. package/server/mention-queue.ts +215 -0
  158. package/server/notes-files.ts +92 -0
  159. package/server/notes-prompt.ts +70 -0
  160. package/server/notes-schedule.ts +113 -0
  161. package/server/notes-writer.ts +356 -0
  162. package/server/office.ts +191 -0
  163. package/server/paseo-directory.ts +114 -0
  164. package/server/paseo-holder.ts +37 -0
  165. package/server/paths.ts +72 -0
  166. package/server/prompt-text.ts +12 -0
  167. package/server/repo-age.ts +26 -0
  168. package/server/schedule-follower.ts +80 -0
  169. package/server/script-log.ts +61 -0
  170. package/server/skills.ts +197 -0
  171. package/server/street-kit.generated.ts +2 -0
  172. package/server/street-watch.ts +143 -0
  173. package/server/subagent-names.ts +88 -0
  174. package/server/tenure.ts +184 -0
  175. package/server/timers.ts +25 -0
  176. package/server/weather-read.ts +132 -0
  177. package/server/weather-service.ts +158 -0
  178. package/server/words.generated.ts +3 -0
  179. package/server/world-script.ts +18 -0
  180. package/server/world-words.ts +17 -0
  181. package/server/world.generated.ts +3 -0
  182. package/shared/chat-words.ts +80 -0
  183. package/shared/contracts.ts +709 -0
  184. package/shared/host-extras.ts +21 -0
  185. package/shared/life-lines.ts +330 -0
  186. package/shared/machine-text.ts +152 -0
  187. package/shared/model.ts +306 -0
  188. package/shared/names.ts +41 -0
  189. package/shared/scene-language.ts +26 -0
  190. package/shared/settings.ts +206 -0
  191. package/shared/standup-report.ts +8 -0
  192. package/shared/standup-text.ts +252 -0
  193. package/shared/upstream/README.md +3 -0
  194. package/shared/upstream/chat-engine.d.ts +97 -0
  195. package/shared/upstream/chat-engine.js +231 -0
  196. package/shared/upstream/chat.d.ts +12 -0
  197. package/shared/upstream/chat.js +387 -0
  198. package/shared/weather.ts +52 -0
@@ -0,0 +1,339 @@
1
+ // The activity feed: what changed between two office states, in words, and the store that keeps
2
+ // the newest of it. Pure derivation plus a module-level store, so the office's surface and a
3
+ // panel that subscribes on its own route feed one feed. Nothing here reaches the server.
4
+ import type { AgentStatus, OfficeAgent, OfficeSnapshot } from "../shared/contracts.js";
5
+ import { agentTitle } from "../shared/model.js";
6
+ import type { ActivityStep } from "../shared/names.js";
7
+ import { eventText, type EventTextExtra, type FeedKind } from "./activity-feed-text.js";
8
+
9
+ export type { FeedKind } from "./activity-feed-text.js";
10
+
11
+ /** An agent's moment in the office, as the feed says it. */
12
+ export interface FeedEvent {
13
+ /** `${agentId}:${what}`: the step's key, the permission's id, or the status and its moment. */
14
+ id: string;
15
+ /** The agent it happened to. A new sub-agent's start is its parent's event. */
16
+ agentId: string;
17
+ /** The office's name for the agent, kept after the agent has left. */
18
+ title: string;
19
+ /** Epoch ms of the read that saw it. */
20
+ at: number;
21
+ kind: FeedKind;
22
+ /** Needs permission and stopped on an error: the events that stand alone in the feed. */
23
+ alert: boolean;
24
+ text: string;
25
+ }
26
+
27
+ export type FeedChip = "cmd" | "edit" | "read" | "web" | "agent";
28
+
29
+ const CHIPS: Readonly<Partial<Record<FeedKind, FeedChip>>> = {
30
+ command: "cmd",
31
+ test: "cmd",
32
+ commit: "cmd",
33
+ push: "cmd",
34
+ deploy: "cmd",
35
+ edit: "edit",
36
+ write: "edit",
37
+ read: "read",
38
+ search: "read",
39
+ skill: "read",
40
+ web: "web",
41
+ tool: "web",
42
+ subagent: "agent",
43
+ plan: "agent",
44
+ "subagent-started": "agent",
45
+ };
46
+
47
+ /** The chip an event shows under; null for the status events, which show under All alone. */
48
+ export function chipOf(kind: FeedKind): FeedChip | null {
49
+ return CHIPS[kind] ?? null;
50
+ }
51
+
52
+ function eventOf(
53
+ agent: OfficeAgent,
54
+ at: number,
55
+ kind: FeedKind,
56
+ what: string,
57
+ extra: EventTextExtra = {},
58
+ ): FeedEvent {
59
+ return {
60
+ id: `${agent.id}:${what}`,
61
+ agentId: agent.id,
62
+ title: agentTitle(agent),
63
+ at,
64
+ kind,
65
+ alert: kind === "permission" || kind === "error",
66
+ text: eventText(kind, extra),
67
+ };
68
+ }
69
+
70
+ /** A status that changed, as the feed says it; null for a change it does not tell. */
71
+ function statusKind(before: AgentStatus, after: AgentStatus): FeedKind | null {
72
+ if (before === after) return null;
73
+ if (after === "running") return "started";
74
+ if (after === "error") return "error";
75
+ return after === "idle" && before === "running" ? "finished" : null;
76
+ }
77
+
78
+ function statusEvents(before: OfficeAgent, after: OfficeAgent, at: number): FeedEvent[] {
79
+ const kind = statusKind(before.status, after.status);
80
+ if (kind === null) return [];
81
+ // The moment it changed: an idle agent says since when; any other is this read.
82
+ return [eventOf(after, at, kind, `${after.status}@${after.idleSince ?? at}`)];
83
+ }
84
+
85
+ function permissionEvents(before: OfficeAgent, after: OfficeAgent, at: number): FeedEvent[] {
86
+ const seen = new Set(before.permissions.map((permission) => permission.id));
87
+ return after.permissions
88
+ .filter((permission) => !seen.has(permission.id))
89
+ .map((permission) =>
90
+ eventOf(after, at, "permission", permission.id, {
91
+ title: permission.title,
92
+ permissionKind: permission.kind,
93
+ }),
94
+ );
95
+ }
96
+
97
+ /**
98
+ * A step's event: the agent moved to a step it was not at, or that step ended badly. The id is
99
+ * the step's key, so a failure replaces the step's own event rather than adding one.
100
+ */
101
+ function stepEvents(
102
+ agent: OfficeAgent,
103
+ before: ActivityStep | undefined,
104
+ after: ActivityStep | undefined,
105
+ at: number,
106
+ ): FeedEvent[] {
107
+ if (after === undefined) return [];
108
+ const moved = before?.key !== after.key;
109
+ const failed = after.result === "failed" && before?.result !== "failed";
110
+ if (!moved && !failed) return [];
111
+ return [eventOf(agent, at, after.kind, after.key, { failed })];
112
+ }
113
+
114
+ /** The event of a sub-agent that appeared under a parent, told as the parent's. */
115
+ function startedSubAgent(parent: OfficeAgent, child: OfficeAgent, at: number): FeedEvent {
116
+ return {
117
+ id: `${parent.id}:subagent:${child.id}`,
118
+ agentId: parent.id,
119
+ title: agentTitle(parent),
120
+ at,
121
+ kind: "subagent-started",
122
+ alert: false,
123
+ text: eventText("subagent-started", { title: agentTitle(child) }),
124
+ };
125
+ }
126
+
127
+ function eventsFor(
128
+ before: OfficeSnapshot,
129
+ after: OfficeSnapshot,
130
+ agent: OfficeAgent,
131
+ at: number,
132
+ ): FeedEvent[] {
133
+ const was = before.agents.find((candidate) => candidate.id === agent.id);
134
+ if (was === undefined) {
135
+ // An agent the office had not shown: told by its status once it changes, never on arrival.
136
+ // A sub-agent is the one exception: the parent started it, which is worth a line.
137
+ const parentId = agent.parentAgentId;
138
+ const parent =
139
+ parentId === null
140
+ ? undefined
141
+ : after.agents.find((candidate) => candidate.id === parentId && candidate.id !== agent.id);
142
+ return parent === undefined ? [] : [startedSubAgent(parent, agent, at)];
143
+ }
144
+ return [
145
+ ...statusEvents(was, agent, at),
146
+ ...permissionEvents(was, agent, at),
147
+ ...stepEvents(agent, before.doing?.[agent.id], after.doing?.[agent.id], at),
148
+ ];
149
+ }
150
+
151
+ /**
152
+ * What changed between two states, in the office's order. The first state has nothing before it:
153
+ * opening the office is no news.
154
+ */
155
+ export function feedEvents(
156
+ before: OfficeSnapshot | null,
157
+ after: OfficeSnapshot,
158
+ now: number,
159
+ ): FeedEvent[] {
160
+ if (before === null) return [];
161
+ return after.agents.flatMap((agent) => eventsFor(before, after, agent, now));
162
+ }
163
+
164
+ /** One card of the feed: an agent's consecutive events, or an alert on its own. */
165
+ export interface FeedCard {
166
+ agentId: string;
167
+ title: string;
168
+ /** The newest event's time: the card's own. */
169
+ at: number;
170
+ /** The newest four lines, newest first. */
171
+ lines: string[];
172
+ /** How many more lines the card holds. */
173
+ more: number;
174
+ /** Needs permission or stopped on an error: the card stands alone and offers its session. */
175
+ alert: boolean;
176
+ }
177
+
178
+ /** Events of one agent this close together share a card: four minutes. */
179
+ export const CARD_GAP_MS = 4 * 60 * 1000;
180
+ /** The lines of a card before "+N more". */
181
+ export const CARD_LINES = 4;
182
+
183
+ export type FeedTab = "all" | "attention";
184
+
185
+ function shown(event: FeedEvent, tab: FeedTab, chips: ReadonlySet<FeedChip>): boolean {
186
+ if (tab === "attention" && !event.alert) return false;
187
+ if (chips.size === 0) return true;
188
+ const chip = chipOf(event.kind);
189
+ return chip !== null && chips.has(chip);
190
+ }
191
+
192
+ /** Newest first; two events of one read keep the later-told first. */
193
+ function byNewest(events: readonly FeedEvent[]): FeedEvent[] {
194
+ return events
195
+ .map((event, index) => ({ event, index }))
196
+ .sort((left, right) => right.event.at - left.event.at || right.index - left.index)
197
+ .map(({ event }) => event);
198
+ }
199
+
200
+ function sharesCard(card: FeedCard, event: FeedEvent): boolean {
201
+ return (
202
+ !card.alert &&
203
+ !event.alert &&
204
+ card.agentId === event.agentId &&
205
+ card.at - event.at <= CARD_GAP_MS
206
+ );
207
+ }
208
+
209
+ function addToCard(card: FeedCard, event: FeedEvent): void {
210
+ if (card.lines.length < CARD_LINES) card.lines.push(event.text);
211
+ else card.more += 1;
212
+ }
213
+
214
+ /**
215
+ * The feed as cards, newest first. The tab keeps the alerts or everything; the chips keep the
216
+ * kinds they name, and no chip keeps all of them.
217
+ */
218
+ export function feedCards(
219
+ events: readonly FeedEvent[],
220
+ tab: FeedTab,
221
+ chips: ReadonlySet<FeedChip>,
222
+ ): FeedCard[] {
223
+ const cards: FeedCard[] = [];
224
+ let open: FeedCard | null = null;
225
+ for (const event of byNewest(events)) {
226
+ if (!shown(event, tab, chips)) continue;
227
+ if (open !== null && sharesCard(open, event)) {
228
+ addToCard(open, event);
229
+ continue;
230
+ }
231
+ open = {
232
+ agentId: event.agentId,
233
+ title: event.title,
234
+ at: event.at,
235
+ lines: [event.text],
236
+ more: 0,
237
+ alert: event.alert,
238
+ };
239
+ cards.push(open);
240
+ }
241
+ return cards;
242
+ }
243
+
244
+ /** The newest events the feed keeps. */
245
+ export const FEED_EVENT_MAX = 300;
246
+
247
+ function sameEvent(left: FeedEvent, right: FeedEvent): boolean {
248
+ return (
249
+ left.at === right.at &&
250
+ left.text === right.text &&
251
+ left.title === right.title &&
252
+ left.alert === right.alert
253
+ );
254
+ }
255
+
256
+ /** Two subscriptions receive the same broadcast milliseconds apart, and stamp its status with each. */
257
+ export const STATUS_SAME_MS = 2_000;
258
+
259
+ const STATUS_KINDS: ReadonlySet<FeedKind> = new Set(["started", "finished", "error"]);
260
+
261
+ /** A status event already kept for the same change: same agent, same kind, close in time. */
262
+ function statusTwin(kept: readonly FeedEvent[], event: FeedEvent): boolean {
263
+ return (
264
+ STATUS_KINDS.has(event.kind) &&
265
+ kept.some(
266
+ (other) =>
267
+ other.agentId === event.agentId &&
268
+ other.kind === event.kind &&
269
+ Math.abs(other.at - event.at) <= STATUS_SAME_MS,
270
+ )
271
+ );
272
+ }
273
+
274
+ let store: readonly FeedEvent[] = [];
275
+ const listeners = new Set<() => void>();
276
+
277
+ function tell(): void {
278
+ for (const listener of listeners) listener();
279
+ }
280
+
281
+ /**
282
+ * The feed's store: one per app run, written by every subscription to the office's state and read
283
+ * by the Activity panel. An event id says what it is, so the same event pushed twice is kept once.
284
+ */
285
+ export const feedStore = {
286
+ push(incoming: readonly FeedEvent[]): void {
287
+ if (incoming.length === 0) return;
288
+ const next = [...store];
289
+ const index = new Map(next.map((event, position) => [event.id, position]));
290
+ let changed = false;
291
+ for (const event of incoming) {
292
+ // The earlier telling of a status change is kept; the other subscription's is dropped.
293
+ if (statusTwin(next, event)) continue;
294
+ const position = index.get(event.id);
295
+ if (position === undefined) {
296
+ index.set(event.id, next.length);
297
+ next.push(event);
298
+ changed = true;
299
+ continue;
300
+ }
301
+ const kept = next[position];
302
+ if (kept !== undefined && sameEvent(kept, event)) continue;
303
+ // The newest telling of an id wins: a test run's end replaces the step it ended.
304
+ next[position] = event;
305
+ changed = true;
306
+ }
307
+ if (!changed) return;
308
+ store = next.length > FEED_EVENT_MAX ? next.slice(next.length - FEED_EVENT_MAX) : next;
309
+ tell();
310
+ },
311
+ subscribe(listener: () => void): () => void {
312
+ listeners.add(listener);
313
+ return () => void listeners.delete(listener);
314
+ },
315
+ getSnapshot(): readonly FeedEvent[] {
316
+ return store;
317
+ },
318
+ /** Tests only: an empty feed, as at the start of an app run. Changes no caller's own state. */
319
+ reset(): void {
320
+ store = [];
321
+ tell();
322
+ },
323
+ };
324
+
325
+ /**
326
+ * Feeds one subscription's change to the store: the state it came from and the state it has now.
327
+ * Each caller brings its own pair, because two subscriptions to the office's state do not share
328
+ * an order, and a pair diffed against another caller's state could run backwards. A first state
329
+ * (`before === null`) says nothing: opening the office is no news. The store makes the same change
330
+ * seen by two callers one event: a step or a permission by its id, a status change by its agent,
331
+ * kind and the `STATUS_SAME_MS` window.
332
+ */
333
+ export function recordOfficeState(
334
+ before: OfficeSnapshot | null,
335
+ after: OfficeSnapshot,
336
+ now: number = Date.now(),
337
+ ): void {
338
+ feedStore.push(feedEvents(before, after, now));
339
+ }
@@ -0,0 +1,306 @@
1
+ import { useCallback, useMemo, useState, useSyncExternalStore } from "react";
2
+ import { Pressable, Text, View } from "react-native";
3
+ import { ScrollView } from "@getpaseo/plugin/client/ui";
4
+ import type { OfficeAgent } from "../shared/contracts.js";
5
+ import { dotTone, type DotTone } from "../shared/model.js";
6
+ import { ActionButton } from "./action-button.js";
7
+ import {
8
+ feedCards,
9
+ feedStore,
10
+ type FeedCard,
11
+ type FeedChip,
12
+ type FeedTab,
13
+ } from "./activity-feed.js";
14
+ import { FEED_EMPTY, FEED_NO_MATCH } from "./activity-feed-text.js";
15
+ import type { ColumnPanelProps, OfficeLink } from "./office-link.js";
16
+ import { problemText } from "./office-surface.js";
17
+ import type { OfficeStyles } from "./styles.js";
18
+ import type { OfficeState } from "./use-office.js";
19
+
20
+ const CHIPS: readonly { chip: FeedChip; label: string }[] = [
21
+ { chip: "cmd", label: "Commands" },
22
+ { chip: "edit", label: "Edits" },
23
+ { chip: "read", label: "Reads" },
24
+ { chip: "web", label: "Web" },
25
+ { chip: "agent", label: "Agents" },
26
+ ];
27
+
28
+ const NO_CHIPS: ReadonlySet<FeedChip> = new Set();
29
+
30
+ /** A card's time: the clock on this device, 24-hour. */
31
+ function clock(at: number): string {
32
+ const date = new Date(at);
33
+ const pad = (value: number) => String(value).padStart(2, "0");
34
+ return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
35
+ }
36
+
37
+ interface PillProps<Value extends string> {
38
+ value: Value;
39
+ label: string;
40
+ /** What a screen reader calls it, when it says more than the label (a count). */
41
+ name?: string;
42
+ count?: number;
43
+ on: boolean;
44
+ /** Not pressable: a screen reader hears it as unavailable. */
45
+ disabled?: boolean;
46
+ /** A chip is a toggle and says it is pressed; a tab says it is the chosen one. */
47
+ compact?: boolean;
48
+ activityChip?: boolean;
49
+ attention?: boolean;
50
+ toggle: boolean;
51
+ onPress(value: Value): void;
52
+ styles: OfficeStyles;
53
+ }
54
+
55
+ /** A tab or a chip: the view switch's pill. */
56
+ export function Pill<Value extends string>({
57
+ value,
58
+ label,
59
+ name,
60
+ count,
61
+ on,
62
+ disabled = false,
63
+ compact = false,
64
+ activityChip = false,
65
+ attention = false,
66
+ toggle,
67
+ onPress,
68
+ styles,
69
+ }: PillProps<Value>) {
70
+ const press = useCallback(() => onPress(value), [onPress, value]);
71
+ const [hovered, setHovered] = useState(false);
72
+ const hoverIn = useCallback(() => setHovered(true), []);
73
+ const hoverOut = useCallback(() => setHovered(false), []);
74
+ const [pressed, setPressed] = useState(false);
75
+ const pressIn = useCallback(() => setPressed(true), []);
76
+ const pressOut = useCallback(() => setPressed(false), []);
77
+ const pillStyle = useMemo(() => {
78
+ if (activityChip) return [styles.segment, styles.activityChip];
79
+ return compact ? [styles.segment, styles.sessionFilter] : styles.segment;
80
+ }, [activityChip, compact, styles]);
81
+ const textStyle = useMemo(() => {
82
+ const labelStyle = on ? styles.segmentTextSelected : styles.segmentText;
83
+ return activityChip ? [labelStyle, styles.activityChipText] : labelStyle;
84
+ }, [activityChip, on, styles]);
85
+ let fill = null;
86
+ if (on) fill = styles.segmentFill;
87
+ else if (hovered || pressed) fill = styles.segmentHoverFill;
88
+ return (
89
+ <Pressable
90
+ accessibilityRole="button"
91
+ accessibilityLabel={name ?? label}
92
+ aria-pressed={toggle ? on : undefined}
93
+ aria-selected={toggle ? undefined : on}
94
+ disabled={disabled}
95
+ onPress={press}
96
+ onPressIn={pressIn}
97
+ onPressOut={pressOut}
98
+ onHoverIn={hoverIn}
99
+ onHoverOut={hoverOut}
100
+ style={pillStyle}
101
+ >
102
+ {fill === null ? null : <View style={fill} />}
103
+ <Text style={textStyle}>
104
+ {label}
105
+ {count === undefined ? null : (
106
+ <Text style={attention && count > 0 ? styles.activityCount : styles.panelCount}>
107
+ {" "}
108
+ {count}
109
+ </Text>
110
+ )}
111
+ </Text>
112
+ </Pressable>
113
+ );
114
+ }
115
+
116
+ interface CardRowProps {
117
+ card: FeedCard;
118
+ /** The card's agent as the office has it now; absent once it has left. */
119
+ agent: OfficeAgent | undefined;
120
+ link: OfficeLink;
121
+ styles: OfficeStyles;
122
+ }
123
+
124
+ function CardRow({ card, agent, link, styles }: CardRowProps) {
125
+ const { agentId } = card;
126
+ const press = useCallback(() => link.select(agentId), [agentId, link]);
127
+ const openSession = useCallback(() => link.openSession(agentId), [agentId, link]);
128
+ const [hovered, setHovered] = useState(false);
129
+ const hoverIn = useCallback(() => setHovered(true), []);
130
+ const hoverOut = useCallback(() => setHovered(false), []);
131
+ const [pressed, setPressed] = useState(false);
132
+ const pressIn = useCallback(() => setPressed(true), []);
133
+ const pressOut = useCallback(() => setPressed(false), []);
134
+ const tone: DotTone = agent === undefined ? "idle" : dotTone(agent);
135
+ const time = clock(card.at);
136
+ const working = agent?.status === "running";
137
+ const cardStyle = useMemo(
138
+ () => [
139
+ styles.activityCard,
140
+ working && styles.activityWorkingCard,
141
+ card.alert && styles.activityAlert,
142
+ ],
143
+ [card.alert, styles, working],
144
+ );
145
+ // Open session sits under the card's pressable, not in it, so its press is its own.
146
+ return (
147
+ <View style={cardStyle}>
148
+ <Pressable
149
+ accessibilityRole="button"
150
+ accessibilityLabel={`${card.title}, ${time}`}
151
+ onPress={press}
152
+ onPressIn={pressIn}
153
+ onPressOut={pressOut}
154
+ onHoverIn={hoverIn}
155
+ onHoverOut={hoverOut}
156
+ style={styles.activityCardBody}
157
+ >
158
+ {pressed || hovered ? <View style={styles.pressedFill} /> : null}
159
+ <View style={styles.activityEntries}>
160
+ <View style={styles.rowHeading}>
161
+ <View style={styles.dot[tone]} />
162
+ <Text style={styles.activityCardTitle} numberOfLines={2}>
163
+ {card.title}
164
+ </Text>
165
+ {working ? <Text style={styles.activityWorking}>Working</Text> : null}
166
+ <Text style={styles.panelTime}>{time}</Text>
167
+ </View>
168
+ {card.lines.map((line, index) => (
169
+ // A card's lines repeat ("Editing" twice), so their place is their key.
170
+ // oxlint-disable-next-line react/no-array-index-key
171
+ <Text key={index} style={styles.activityLine}>
172
+ {line}
173
+ </Text>
174
+ ))}
175
+ {card.more > 0 ? <Text style={styles.rowMeta}>+{card.more} more</Text> : null}
176
+ </View>
177
+ </Pressable>
178
+ {card.alert ? (
179
+ <View style={styles.activityActions}>
180
+ <ActionButton
181
+ label="Open session"
182
+ pendingLabel="Opening..."
183
+ onPress={openSession}
184
+ styles={styles}
185
+ />
186
+ </View>
187
+ ) : null}
188
+ </View>
189
+ );
190
+ }
191
+
192
+ /** The office's own words for a state that cannot load, as its surface shows them. */
193
+ export function loadProblem(subscription: OfficeState["subscription"]): string | null {
194
+ if (subscription.status === "error") {
195
+ return problemText("Unable to load the office", subscription.error.message);
196
+ }
197
+ if (subscription.status === "closed") {
198
+ return "Unable to show live agents: the host closed the office. Reopen it.";
199
+ }
200
+ return null;
201
+ }
202
+
203
+ /**
204
+ * The Activity tab of the office's column, fed by the surface's subscription: the feed of what
205
+ * the agents did, filtered by its tabs and chips.
206
+ */
207
+ export function ActivityPanel({ office, styles, link }: ColumnPanelProps) {
208
+ const { state, subscription } = office;
209
+ const events = useSyncExternalStore(feedStore.subscribe, feedStore.getSnapshot);
210
+ const [tab, setTab] = useState<FeedTab>("all");
211
+ const [chips, setChips] = useState<ReadonlySet<FeedChip>>(NO_CHIPS);
212
+ const cards = useMemo(() => feedCards(events, tab, chips), [events, tab, chips]);
213
+ const needsYou = useMemo(() => feedCards(events, "attention", NO_CHIPS).length, [events]);
214
+ const agents = useMemo(
215
+ () => new Map(state.agents.map((agent) => [agent.id, agent])),
216
+ [state.agents],
217
+ );
218
+ const toggle = useCallback((chip: FeedChip) => {
219
+ setChips((current) => {
220
+ const next = new Set(current);
221
+ if (!next.delete(chip)) next.add(chip);
222
+ return next;
223
+ });
224
+ }, []);
225
+ const problem = loadProblem(subscription);
226
+ return (
227
+ <View style={styles.screen}>
228
+ <ScrollView contentContainerStyle={styles.panelFeed}>
229
+ <View style={styles.activityTop}>
230
+ <View style={styles.activityHeading}>
231
+ <Text accessibilityRole="header" style={styles.activityTitle}>
232
+ Activity
233
+ </Text>
234
+ {subscription.status === "live" ? (
235
+ <View style={styles.panelLive}>
236
+ <View style={styles.dot.running} />
237
+ <Text style={styles.panelLiveText}>Live</Text>
238
+ </View>
239
+ ) : null}
240
+ </View>
241
+ <View role="group" aria-label="Feed" style={styles.activityTabs}>
242
+ <Pill<FeedTab>
243
+ value="all"
244
+ label="All"
245
+ on={tab === "all"}
246
+ compact
247
+ toggle={false}
248
+ onPress={setTab}
249
+ styles={styles}
250
+ />
251
+ <Pill<FeedTab>
252
+ value="attention"
253
+ label="Needs you"
254
+ name={`Needs you, ${needsYou}`}
255
+ count={needsYou}
256
+ attention
257
+ on={tab === "attention"}
258
+ compact
259
+ toggle={false}
260
+ onPress={setTab}
261
+ styles={styles}
262
+ />
263
+ </View>
264
+ <View role="group" aria-label="Kinds" style={styles.activityChips}>
265
+ {CHIPS.map(({ chip, label }) => (
266
+ <Pill
267
+ key={chip}
268
+ activityChip
269
+ label={label}
270
+ on={chips.has(chip)}
271
+ toggle
272
+ value={chip}
273
+ onPress={toggle}
274
+ styles={styles}
275
+ />
276
+ ))}
277
+ </View>
278
+ </View>
279
+ {problem === null ? null : (
280
+ <View style={styles.bannerSlot}>
281
+ <View style={styles.banner}>
282
+ <Text accessibilityRole="alert" style={styles.bannerText}>
283
+ {problem}
284
+ </Text>
285
+ </View>
286
+ </View>
287
+ )}
288
+ {events.length === 0 ? <Text style={styles.sceneStatus}>{FEED_EMPTY}</Text> : null}
289
+ {events.length > 0 && cards.length === 0 ? (
290
+ <Text style={styles.sceneStatus}>{FEED_NO_MATCH}</Text>
291
+ ) : null}
292
+ {cards.map((card, index) => (
293
+ <CardRow
294
+ // A card has no id, and two alerts of one agent can share a moment and a text.
295
+ // oxlint-disable-next-line react/no-array-index-key
296
+ key={`${card.agentId}:${card.at}:${index}`}
297
+ card={card}
298
+ agent={agents.get(card.agentId)}
299
+ link={link}
300
+ styles={styles}
301
+ />
302
+ ))}
303
+ </ScrollView>
304
+ </View>
305
+ );
306
+ }