paseo-office 0.2.0 → 0.2.2

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 (143) hide show
  1. package/OVERVIEW.md +27 -0
  2. package/README.md +65 -134
  3. package/client/action-button.tsx +4 -1
  4. package/client/activity-panel.tsx +6 -4
  5. package/client/agent-appearance.tsx +257 -0
  6. package/client/agent-card.tsx +2 -1
  7. package/client/agent-picker-text.ts +23 -4
  8. package/client/agent-picker.tsx +5 -8
  9. package/client/board-sheet.tsx +48 -16
  10. package/client/board-text.ts +12 -2
  11. package/client/brand.ts +1 -0
  12. package/client/chat-chrome.tsx +318 -0
  13. package/client/chat-compose-tools.tsx +314 -0
  14. package/client/chat-dictation.tsx +133 -0
  15. package/client/chat-more.tsx +119 -0
  16. package/client/chat-panel.tsx +401 -146
  17. package/client/chat-quick.tsx +198 -0
  18. package/client/chat-text.ts +25 -6
  19. package/client/column-sheet.tsx +93 -23
  20. package/client/conversation-model.ts +19 -5
  21. package/client/duty-sheet.tsx +321 -0
  22. package/client/duty-text.ts +20 -0
  23. package/client/fullscreen-header.tsx +28 -13
  24. package/client/fullscreen-theme.ts +38 -0
  25. package/client/host-details.tsx +269 -0
  26. package/client/host-styles.ts +129 -0
  27. package/client/host-switches.tsx +212 -83
  28. package/client/incidents-card.tsx +2 -1
  29. package/client/janitor-card.tsx +1 -1
  30. package/client/library-card.tsx +2 -1
  31. package/client/list-text.ts +8 -6
  32. package/client/lobby-board.tsx +73 -53
  33. package/client/machine-card.tsx +225 -85
  34. package/client/messenger-styles.ts +216 -0
  35. package/client/new-agent-form.tsx +153 -61
  36. package/client/new-agent-model.ts +2 -0
  37. package/client/notes-card.tsx +111 -83
  38. package/client/notes-days.tsx +1 -1
  39. package/client/office-brand-context.ts +44 -0
  40. package/client/office-column.tsx +2 -1
  41. package/client/office-keyboard.ts +79 -0
  42. package/client/office-link.ts +7 -1
  43. package/client/office-mark.tsx +29 -0
  44. package/client/office-modal.tsx +440 -0
  45. package/client/office-settings.tsx +75 -30
  46. package/client/office-state.ts +12 -2
  47. package/client/office-surface.tsx +591 -81
  48. package/client/pixel/actors.ts +2 -1
  49. package/client/pixel/art.ts +33 -19
  50. package/client/pixel/pixel-office.tsx +2 -2
  51. package/client/prompt-coach.tsx +152 -0
  52. package/client/qa-card.tsx +2 -1
  53. package/client/review-card.tsx +2 -1
  54. package/client/room-board.tsx +26 -2
  55. package/client/scene-picker.tsx +158 -0
  56. package/client/scene-previews.ts +10 -0
  57. package/client/session-pane.tsx +25 -5
  58. package/client/session-panel-detail.tsx +238 -0
  59. package/client/session-panel.tsx +222 -137
  60. package/client/session-styles.ts +224 -1
  61. package/client/session-transcript.tsx +243 -0
  62. package/client/sessions-panel.tsx +181 -22
  63. package/client/sessions-text.ts +18 -0
  64. package/client/settings-sections.tsx +126 -0
  65. package/client/sidebar-launcher.ts +29 -0
  66. package/client/ssh-hosts.tsx +331 -0
  67. package/client/ssh-metrics.ts +76 -0
  68. package/client/standup-card.tsx +2 -1
  69. package/client/structure-view.tsx +20 -3
  70. package/client/styles.ts +170 -62
  71. package/client/team-chat-preview.tsx +96 -0
  72. package/client/tracker-connections.tsx +252 -0
  73. package/client/transcript-styles.ts +90 -0
  74. package/client/use-device-switch.ts +21 -12
  75. package/client/use-duty-actions.ts +43 -0
  76. package/client/use-group-photo.ts +48 -0
  77. package/client/use-new-agent.ts +4 -0
  78. package/client/use-street.ts +8 -0
  79. package/client/workspace-office-tools.tsx +102 -0
  80. package/client/workspace-overlay-route.web.ts +47 -0
  81. package/client/workspace-overlay.tsx +195 -0
  82. package/client/world/adapter.ts +37 -2
  83. package/client/world/escape.ts +58 -0
  84. package/client/world/use-world-feed.ts +6 -2
  85. package/client/world/workspace-dock.ts +6 -0
  86. package/client/world/world-api.ts +45 -4
  87. package/client/world/world-bridge-page.ts +14 -3
  88. package/client/world/world-bridge.ts +50 -5
  89. package/client/world/world-frame.web.ts +8 -0
  90. package/client/world/world-view-native.tsx +31 -10
  91. package/client/world/world-view-shared.ts +36 -7
  92. package/client/world/world-view.tsx +93 -21
  93. package/docs/office.md +165 -64
  94. package/index.client.tsx +13 -6
  95. package/index.server.ts +232 -16
  96. package/package.json +2 -1
  97. package/server/activity.ts +42 -19
  98. package/server/agent-tools.ts +11 -5
  99. package/server/board-service.ts +381 -10
  100. package/server/brand-logo.ts +34 -0
  101. package/server/chat-group.ts +83 -0
  102. package/server/chat-service.ts +406 -62
  103. package/server/chat-store.ts +1 -4
  104. package/server/directory.ts +22 -7
  105. package/server/duty-service.ts +230 -0
  106. package/server/group-photo.ts +39 -0
  107. package/server/home-departure.ts +47 -0
  108. package/server/hub.ts +43 -1
  109. package/server/incidents-jira.ts +19 -7
  110. package/server/incidents-schedule.ts +10 -10
  111. package/server/incidents-sentry.ts +34 -8
  112. package/server/live-ports.ts +114 -18
  113. package/server/lobby-pickup.ts +170 -0
  114. package/server/machine/details.ts +91 -0
  115. package/server/mention-queue.ts +14 -0
  116. package/server/office.ts +110 -6
  117. package/server/paths.ts +14 -0
  118. package/server/ssh/LICENSE.paseo +211 -0
  119. package/server/ssh/client.ts +401 -0
  120. package/server/ssh/discovery.ts +230 -0
  121. package/server/ssh/installed.ts +104 -0
  122. package/server/ssh/monitor.ts +104 -0
  123. package/server/ssh/pid-files.ts +194 -0
  124. package/server/ssh/read.ts +136 -0
  125. package/server/subagent-names.ts +4 -0
  126. package/server/tracker-credentials.ts +141 -0
  127. package/server/words.generated.ts +1 -1
  128. package/server/world.generated.ts +1 -1
  129. package/shared/appearance.ts +43 -0
  130. package/shared/branding.ts +53 -0
  131. package/shared/chat-words.ts +2 -2
  132. package/shared/contracts.ts +199 -5
  133. package/shared/duties.ts +100 -0
  134. package/shared/host-details.ts +25 -0
  135. package/shared/lobby-assignment.ts +34 -0
  136. package/shared/model.ts +9 -1
  137. package/shared/names.ts +2 -0
  138. package/shared/settings.ts +14 -3
  139. package/shared/ssh.ts +34 -0
  140. package/shared/upstream/README.md +1 -3
  141. package/shared/upstream/chat-engine.d.ts +4 -0
  142. package/shared/upstream/prompt-coach.d.ts +6 -0
  143. package/shared/upstream/prompt-coach.js +178 -0
package/index.server.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { createLogoReader } from "./server/brand-logo.js";
2
+ import { hostBrand } from "./shared/branding.js";
1
3
  import { createHash } from "node:crypto";
2
4
  import { execCommand } from "@getpaseo/plugin/server";
3
5
  import { createTenure, TenureLedgerSchema, type TenureLedger } from "./server/tenure.js";
@@ -8,7 +10,13 @@ import { streetSubscription } from "./shared/contracts.js";
8
10
  import { createLifeFeed } from "./server/life-feed.js";
9
11
  import { createLifeFile, createSaveQueue, type LifeFile } from "./server/life-store.js";
10
12
  import { liftFile, tenureFile } from "./server/paths.js";
11
- import { lifeSubscription, tenureRpc, type LifeEvent } from "./shared/contracts.js";
13
+ import { createDepartureArchiver } from "./server/home-departure.js";
14
+ import {
15
+ lifeSubscription,
16
+ homeDepartureRpc,
17
+ tenureRpc,
18
+ type LifeEvent,
19
+ } from "./shared/contracts.js";
12
20
  import { embeddedWorldWords, type WorldWords } from "./server/world-words.js";
13
21
  import { homedir } from "node:os";
14
22
  import { setTimeout as delay } from "node:timers/promises";
@@ -26,14 +34,23 @@ import { createHub } from "./server/hub.js";
26
34
  import { createWeatherService } from "./server/weather-service.js";
27
35
  import { createWeatherReader } from "./server/weather-read.js";
28
36
  import { createIncidentsCheck, type IncidentsCheckState } from "./server/incidents-check.js";
29
- import { jiraEnv } from "./server/incidents-jira.js";
37
+ import { TrackerProblem } from "./server/incidents-http.js";
38
+ import { probeJira } from "./server/incidents-jira.js";
30
39
  import {
31
40
  createIncidentsSchedule,
32
41
  INCIDENTS_SCHEDULE,
33
42
  incidentsReaders,
43
+ type IncidentsSettings,
34
44
  } from "./server/incidents-schedule.js";
35
- import { sentryToken } from "./server/incidents-sentry.js";
45
+ import { probeSentry } from "./server/incidents-sentry.js";
36
46
  import { createIncidentsStore, type IncidentsStore } from "./server/incidents-store.js";
47
+ import {
48
+ changeSavedTrackers,
49
+ createTrackerCredentialsStore,
50
+ NO_SAVED_TRACKERS,
51
+ trackerCredentials,
52
+ type TrackerCredentialsStore,
53
+ } from "./server/tracker-credentials.js";
37
54
  import { tidyAgent } from "./server/janitor.js";
38
55
  import {
39
56
  liveAgentPorts,
@@ -44,8 +61,12 @@ import {
44
61
  liveScriptLogPorts,
45
62
  liveSkillsPorts,
46
63
  } from "./server/live-ports.js";
64
+ import { createSshMonitor } from "./server/ssh/monitor.js";
65
+ import { sshReadingRpc, sshServersRpc } from "./shared/ssh.js";
47
66
  import { cleanUpAgent } from "./server/machine/cleanup.js";
48
67
  import { liveCleanupPorts, liveMachinePorts } from "./server/machine/live-ports.js";
68
+ import { hostDetailsRpc, type HostSample } from "./shared/host-details.js";
69
+ import { readHostDetails, recordSample } from "./server/machine/details.js";
49
70
  import { createMachineReader } from "./server/machine/machine.js";
50
71
  import { createMachineWatch } from "./server/machine/watch.js";
51
72
  import { nodeNotesFs, readMonthNotes } from "./server/notes-files.js";
@@ -57,13 +78,21 @@ import {
57
78
  } from "./server/notes-schedule.js";
58
79
  import { createNotesStore, createNotesWriter, type NotesStore } from "./server/notes-writer.js";
59
80
  import { createLocalSchedules, type LocalSchedules } from "./server/local-schedules.js";
81
+ import {
82
+ DUTY_SCHEDULE,
83
+ createDutyService,
84
+ dutiesFileStore,
85
+ type DutiesFile,
86
+ } from "./server/duty-service.js";
60
87
  import { createOffice } from "./server/office.js";
61
88
  import { createPaseoHolder } from "./server/paseo-holder.js";
62
89
  import {
63
90
  boardsFile,
64
91
  chatFile,
92
+ dutiesFile,
65
93
  hostSkillFolders,
66
94
  incidentsFile,
95
+ trackersFile,
67
96
  notesWriterFile,
68
97
  type SkillFolder,
69
98
  } from "./server/paths.js";
@@ -75,7 +104,14 @@ import {
75
104
  cleanupRpc,
76
105
  clearDoneRpc,
77
106
  deleteRpc,
107
+ dutiesSaveRpc,
108
+ dutyActedRpc,
78
109
  incidentsDismissRpc,
110
+ trackersSaveRpc,
111
+ trackersTestRpc,
112
+ type TrackersChange,
113
+ type TrackersProbe,
114
+ type TrackersResult,
79
115
  janitorRpc,
80
116
  machineSubscription,
81
117
  notesReadRpc,
@@ -86,6 +122,7 @@ import {
86
122
  setWakesPausedRpc,
87
123
  skillsRpc,
88
124
  updateRpc,
125
+ worldLogoRpc,
89
126
  worldRpc,
90
127
  streetRpc,
91
128
  worldWordsRpc,
@@ -101,11 +138,15 @@ export interface OfficePluginDeps {
101
138
  notesStore: NotesStore;
102
139
  /** Where the incidents check keeps the open incidents and what each tracker has shown. */
103
140
  incidentsStore: IncidentsStore;
141
+ /** Where the tracker connections saved from the settings are kept. */
142
+ trackerStore: TrackerCredentialsStore;
104
143
  /** Where the team chat keeps its conversation. */
105
144
  chatStore: ChatStore;
106
145
  tenureFile: LifeFile<TenureLedger>;
107
146
  liftFile: LifeFile<LiftKept>;
108
- /** The daemon's environment: the trackers' tokens are read from it. */
147
+ /** The owner's duty list. */
148
+ dutiesFile: LifeFile<DutiesFile>;
149
+ /** The daemon's environment: a tracker with no saved connection takes its token from it. */
109
150
  env: NodeJS.ProcessEnv;
110
151
  clock: Clock;
111
152
  log(message: string): void;
@@ -134,6 +175,16 @@ export interface MachineHost {
134
175
  sleep(ms: number): Promise<void>;
135
176
  }
136
177
 
178
+ /** `zone`, or `hostTimeZone` when this host's Intl does not know it. */
179
+ function knownZone(zone: string, hostTimeZone: string): string {
180
+ try {
181
+ Intl.DateTimeFormat("en-US", { timeZone: zone });
182
+ return zone;
183
+ } catch {
184
+ return hostTimeZone;
185
+ }
186
+ }
187
+
137
188
  /** Why a turn did not complete, for the notes writer; null for one that did. */
138
189
  function turnProblem(outcome: PluginTurnOutcome): string | null {
139
190
  switch (outcome.kind) {
@@ -154,6 +205,7 @@ export function createOfficePlugin(
154
205
  const { log } = deps;
155
206
  const holder = createPaseoHolder();
156
207
  const hub = createHub(liveHubPorts(holder, deps.clock, log));
208
+ hub.setBrand(hostBrand({}, deps.env));
157
209
  const office = createOffice({
158
210
  store: deps.store,
159
211
  clock: deps.clock,
@@ -162,16 +214,23 @@ export function createOfficePlugin(
162
214
  log,
163
215
  });
164
216
 
217
+ const samples: HostSample[] = [];
218
+ const reader = createMachineReader({
219
+ procRoot: deps.machine.procRoot,
220
+ cgroupRoot: deps.machine.cgroupRoot,
221
+ platform: deps.machine.platform,
222
+ ...liveMachinePorts(holder, () => deps.clock.now()),
223
+ });
165
224
  const machine = createMachineWatch({
166
- read: createMachineReader({
167
- procRoot: deps.machine.procRoot,
168
- cgroupRoot: deps.machine.cgroupRoot,
169
- platform: deps.machine.platform,
170
- ...liveMachinePorts(holder, () => deps.clock.now()),
171
- }).read,
225
+ async read() {
226
+ const reading = await reader.read();
227
+ if (reading) recordSample(samples, reading);
228
+ return reading;
229
+ },
172
230
  timers: deps.clock,
173
231
  log,
174
232
  });
233
+ const ssh = createSshMonitor(deps.env, homedir(), deps.machine.procRoot);
175
234
  const cleanupPorts = {
176
235
  procRoot: deps.machine.procRoot,
177
236
  selfPid: deps.machine.selfPid,
@@ -227,23 +286,62 @@ export function createOfficePlugin(
227
286
  changed: (state) => hub.setNotes({ ...state, scheduleError: notesSchedule.error() }),
228
287
  log,
229
288
  });
289
+ // The duty list, posted on the duty board at 08:00 in the notes' zone, and caught up at the
290
+ // start and at each save. A zone that cannot be read, or that Intl does not know, is the host's.
291
+ const duties = createDutyService({
292
+ file: deps.dutiesFile,
293
+ board: office,
294
+ schedules: deps.schedules,
295
+ zone: () =>
296
+ readHostSettings().then(
297
+ (values) => knownZone(notesTimeZone(values, deps.hostTimeZone), deps.hostTimeZone),
298
+ () => deps.hostTimeZone,
299
+ ),
300
+ now: () => deps.clock.now(),
301
+ listed: (list) => office.setDuties(list),
302
+ changed: (state) => hub.setDuties(state),
303
+ log,
304
+ });
305
+ void duties.start();
230
306
  // Every 5 minutes while a tracker is on; it follows the settings as the 8:00 schedule does.
231
307
  const incidentsSchedule = createIncidentsSchedule({ schedules: deps.schedules, log });
232
308
  // The check's last state, kept so a save that changes the schedule's error pushes it again.
233
309
  // Null until the store was read: the snapshot has no incidents before then.
234
310
  let checked: IncidentsCheckState | null = null;
311
+ // The connections saved from the settings, read once and kept: a save replaces them here too.
312
+ let savedTrackers = NO_SAVED_TRACKERS;
313
+ const trackersLoaded = deps.trackerStore.load().then(
314
+ (saved) => {
315
+ savedTrackers = saved;
316
+ return undefined;
317
+ },
318
+ (error: unknown) => log(`[office] tracker connections failed to load: ${errorMessage(error)}`),
319
+ );
320
+ const credentials = () => trackerCredentials(savedTrackers, deps.env);
235
321
  function pushIncidents(): void {
236
322
  if (checked === null) return;
323
+ const { jira, sentry } = credentials();
237
324
  hub.setIncidents({
238
325
  ...checked,
239
- jiraReady: jiraEnv(deps.env) !== null,
240
- sentryReady: sentryToken(deps.env) !== null,
326
+ jiraReady: jira !== null,
327
+ sentryReady: sentry !== null,
328
+ connections: {
329
+ jira: {
330
+ source: jira?.source ?? "none",
331
+ baseUrl: jira?.baseUrl ?? "",
332
+ email: jira?.email ?? "",
333
+ },
334
+ sentry: { source: sentry?.source ?? "none" },
335
+ },
241
336
  scheduleError: incidentsSchedule.error(),
242
337
  });
243
338
  }
244
339
  // The settings are read at each run, so a save holds from the next check.
245
340
  const incidents = createIncidentsCheck({
246
- readers: async () => incidentsReaders(await readHostSettings(), deps.env),
341
+ readers: async () => {
342
+ await trackersLoaded;
343
+ return incidentsReaders(await readHostSettings(), credentials());
344
+ },
247
345
  store: deps.incidentsStore,
248
346
  now: () => deps.clock.now(),
249
347
  log,
@@ -307,12 +405,14 @@ export function createOfficePlugin(
307
405
  // then the chat call waits, and a snapshot has no chat.
308
406
  let chat: ChatService | null = null;
309
407
  let stopWatching: (() => void) | null = null;
408
+ const chatPorts = liveChatPorts(holder);
310
409
  async function startChat(): Promise<void> {
311
410
  const service = await createChatService({
312
411
  store: deps.chatStore,
412
+ lobbyPosts: office.lobbyPosts,
313
413
  clock: deps.clock,
314
414
  tr: chatT,
315
- ...liveChatPorts(holder),
415
+ ...chatPorts,
316
416
  emit: (change) => hub.chatChange(change),
317
417
  log,
318
418
  });
@@ -323,14 +423,20 @@ export function createOfficePlugin(
323
423
  const chatReady = startChat().catch((error: unknown) =>
324
424
  log(`[office] chat unavailable: ${errorMessage(error)}`),
325
425
  );
426
+ let agentToolsOn = false;
427
+ void holder.wait().then(() => office.setPickupEnabled(agentToolsOn));
326
428
  // Neither schedule can follow settings it cannot read: both cards say why until a save is read.
327
429
  function settingsUnreadable(reason: string): void {
430
+ agentToolsOn = false;
431
+ office.setPickupEnabled(false);
328
432
  const message = `The office's settings cannot be read: ${reason}`;
329
433
  log(`[office] ${message}`);
330
434
  notesSchedule.fail(message);
331
435
  incidentsSchedule.fail(message);
332
436
  hub.setNotes({ ...writer.state(), scheduleError: notesSchedule.error() });
333
437
  pushIncidents();
438
+ // The duty board's zone is then the host's, so its 8:00 run still comes.
439
+ void duties.settingsChanged();
334
440
  }
335
441
  async function followSettings(
336
442
  state: PluginSettingsState<typeof officeHostSettings.schema>,
@@ -339,13 +445,21 @@ export function createOfficePlugin(
339
445
  settingsUnreadable(state.error);
340
446
  return;
341
447
  }
448
+ hub.setBrand(hostBrand(state.values, deps.env));
449
+ agentToolsOn = state.values.agentTools;
450
+ office.setPickupEnabled(agentToolsOn && holder.held());
342
451
  weather.settingsChanged(state.values);
343
452
  await notesSchedule.sync(state.values);
453
+ await duties.settingsChanged();
344
454
  // The writer reads the folder again, and its push carries the schedule's error with it.
345
455
  await writer
346
456
  .settingsChanged()
347
457
  .catch((error: unknown) => log(`[office] notes state failed: ${errorMessage(error)}`));
348
- const trackersOn = Object.keys(incidentsReaders(state.values, deps.env)).length > 0;
458
+ await followTrackers(state.values);
459
+ }
460
+ async function followTrackers(values: IncidentsSettings): Promise<void> {
461
+ await trackersLoaded;
462
+ const trackersOn = Object.keys(incidentsReaders(values, credentials())).length > 0;
349
463
  await incidentsSchedule.sync(trackersOn);
350
464
  // With every tracker off no run comes again. One run with no reader drops the problems and
351
465
  // closes what is a day old.
@@ -376,9 +490,18 @@ export function createOfficePlugin(
376
490
  return hub.attach(context);
377
491
  });
378
492
  server.handle(streetRpc, () => guarded("street", () => deps.world.readStreet()));
493
+ const readLogo = createLogoReader();
494
+ server.handle(worldLogoRpc, async () => {
495
+ const current = await settings.read();
496
+ const url = hostBrand(current.status === "ready" ? current.values : {}, deps.env)?.logoUrl;
497
+ return url ? { url, data: await readLogo(url) } : null;
498
+ });
379
499
  server.handle(worldRpc, () => guarded("world", () => deps.world.read()));
380
500
  server.handle(worldWordsRpc, (input) => guarded("words", () => deps.words.read(input.language)));
381
501
  // The readings stop with the last subscriber: nothing walks /proc while no office is open.
502
+ server.handle(sshServersRpc, (_input, context) => ssh.list(context.paseo));
503
+ server.handle(sshReadingRpc, ({ id }, context) => ssh.read(context.paseo, id));
504
+ server.handle(hostDetailsRpc, () => readHostDetails(deps.machine.procRoot, homedir(), samples));
382
505
  server.handle(machineSubscription, (_input, context) => {
383
506
  holder.remember(context.paseo);
384
507
  return machine.attach(context);
@@ -439,6 +562,14 @@ export function createOfficePlugin(
439
562
  holder.remember(context.paseo);
440
563
  return guarded("pause", () => office.setWakesPaused(input.paused));
441
564
  });
565
+ server.handle(dutiesSaveRpc, (input, context) => {
566
+ holder.remember(context.paseo);
567
+ return guarded("duties save", () => duties.save(input.duties));
568
+ });
569
+ server.handle(dutyActedRpc, (input, context) => {
570
+ holder.remember(context.paseo);
571
+ return guarded("duty acted", () => office.actDuty(input.id, input.agentId));
572
+ });
442
573
  // The bell. A start never rejects: why none started is in the snapshot's notes.
443
574
  server.handle(notesWriteRpc, (_input, context) => {
444
575
  holder.remember(context.paseo);
@@ -472,9 +603,64 @@ export function createOfficePlugin(
472
603
  }
473
604
  await writer.start();
474
605
  });
606
+ // The duty board's day: what is due is posted, and done duties of earlier days leave.
607
+ const stopDutyRuns = deps.schedules.handle(DUTY_SCHEDULE, (dueAt) => duties.sync(dueAt));
475
608
  server.handle(incidentsDismissRpc, ({ ids }) =>
476
609
  guarded("incidents dismiss", async () => ({ dismissed: await incidents.dismiss(ids) })),
477
610
  );
611
+ async function saveTrackers(input: TrackersChange): Promise<TrackersResult> {
612
+ await trackersLoaded;
613
+ const changed = changeSavedTrackers(savedTrackers, input);
614
+ if ("problem" in changed) return { ok: false, problem: changed.problem };
615
+ await deps.trackerStore.save(changed.saved);
616
+ savedTrackers = changed.saved;
617
+ // The check's schedule follows the new connection; the settings may be unreadable.
618
+ await readHostSettings().then(followTrackers, pushIncidents);
619
+ return { ok: true };
620
+ }
621
+ async function probeTracker(input: TrackersProbe): Promise<void | string> {
622
+ const kept = credentials();
623
+ if (input.tracker === "jira") {
624
+ // The typed connection as a save would keep it, with the token in use when none is typed.
625
+ const token = input.token.trim() || (kept.jira?.token ?? "");
626
+ const typed = changeSavedTrackers(NO_SAVED_TRACKERS, {
627
+ action: "save-jira",
628
+ ...input,
629
+ token,
630
+ });
631
+ if ("problem" in typed) return typed.problem;
632
+ if (typed.saved.jira === undefined) return "Enter the Jira connection";
633
+ return probeJira({ ...typed.saved.jira, tokenVariable: "the Jira API token" });
634
+ }
635
+ const token = input.token.trim() || (kept.sentry?.token ?? "");
636
+ if (token === "") return "Enter the Sentry auth token";
637
+ const { sentryUrl: url, sentryOrg: org } = await readHostSettings();
638
+ if (org.trim() === "") return "Set the Sentry organisation first";
639
+ return probeSentry({ url, org, token, tokenVariable: "the Sentry auth token" });
640
+ }
641
+ async function testTracker(input: TrackersProbe): Promise<TrackersResult> {
642
+ await trackersLoaded;
643
+ try {
644
+ const problem = await probeTracker(input);
645
+ return typeof problem === "string" ? { ok: false, problem } : { ok: true };
646
+ } catch (error) {
647
+ // A tracker's problem is written to be shown; anything else may quote what was typed.
648
+ if (error instanceof TrackerProblem) return { ok: false, problem: error.message };
649
+ throw error;
650
+ }
651
+ }
652
+ // One save at a time: each starts from what the one before it kept.
653
+ let trackerSaves: Promise<unknown> = Promise.resolve();
654
+ server.handle(trackersSaveRpc, (input) => {
655
+ const run = trackerSaves.then(() =>
656
+ guarded("tracker connection save", () => saveTrackers(input)),
657
+ );
658
+ trackerSaves = run.catch(() => undefined);
659
+ return run;
660
+ });
661
+ server.handle(trackersTestRpc, (input) =>
662
+ guarded("tracker connection test", () => testTracker(input)),
663
+ );
478
664
  server.handle(chatRpc, (input, context) => {
479
665
  holder.remember(context.paseo);
480
666
  return guarded("chat", async () => {
@@ -504,6 +690,19 @@ export function createOfficePlugin(
504
690
  });
505
691
  });
506
692
  server.handle(streetSubscription, (_input, context) => streets.attach(context));
693
+ const archiveDeparture = createDepartureArchiver(
694
+ () => hub.read(),
695
+ async () => {
696
+ const state = await settings.read();
697
+ return state.status === "ready" && state.values.archiveOnDeparture === true;
698
+ },
699
+ );
700
+ server.handle(homeDepartureRpc, (input, context) =>
701
+ guarded("home departure", async () => {
702
+ holder.remember(context.paseo);
703
+ return { archived: await archiveDeparture(context.paseo, input.agentId, input.idleSince) };
704
+ }),
705
+ );
507
706
  server.handle(tenureRpc, async (input, context) => {
508
707
  holder.remember(context.paseo);
509
708
  return (await lifeReady)?.write(input) ?? { ok: false };
@@ -540,6 +739,16 @@ export function createOfficePlugin(
540
739
  holder.remember(context.paseo);
541
740
  office.noteAgent(agent);
542
741
  office.turnEnded(agent.id);
742
+ if (outcome.kind === "completed" && turnId !== null) {
743
+ await office
744
+ .checkCompletion(
745
+ agent.id,
746
+ async () => (await chatPorts.readTurn(agent.id, turnId)).text,
747
+ )
748
+ .catch((error: unknown) =>
749
+ log(`[office] lobby completion check failed: ${errorMessage(error)}`),
750
+ );
751
+ }
543
752
  await (
544
753
  await lifeReady
545
754
  )?.turnEnded(agent.id, async () => {
@@ -609,6 +818,7 @@ export function createOfficePlugin(
609
818
  stopWatchingWeather();
610
819
  weather.stop();
611
820
  stopNotesRuns();
821
+ stopDutyRuns();
612
822
  stopIncidentsRuns();
613
823
  deps.schedules.stop();
614
824
  for (const remove of removeHooks) remove();
@@ -619,7 +829,8 @@ export function createOfficePlugin(
619
829
  for (const close of listeners.values()) close();
620
830
  await Promise.all([tenureSaves.flush(), liftSaved]);
621
831
  machine.stop();
622
- office.stop();
832
+ await ssh.stop();
833
+ await office.stop();
623
834
  // A chat still loading would start its clock after this stop.
624
835
  await chatReady;
625
836
  stopWatching?.();
@@ -640,8 +851,13 @@ export default function contribute(server: PluginServerContext): () => Promise<v
640
851
  }),
641
852
  notesStore: createNotesStore({ file: notesWriterFile(process.env, homedir()), log }),
642
853
  incidentsStore: createIncidentsStore({ file: incidentsFile(process.env, homedir()), log }),
854
+ trackerStore: createTrackerCredentialsStore({
855
+ file: trackersFile(process.env, homedir()),
856
+ log,
857
+ }),
643
858
  tenureFile: createLifeFile(tenureFile(process.env, homedir()), TenureLedgerSchema),
644
859
  liftFile: createLifeFile(liftFile(process.env, homedir()), LiftKeptSchema),
860
+ dutiesFile: dutiesFileStore(dutiesFile(process.env, homedir()), { now: () => Date.now(), log }),
645
861
  chatStore: createChatStore({
646
862
  file: chatFile(process.env, homedir()),
647
863
  now: () => Date.now(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-office",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A community port of my-office for Paseo: your agents at their desks, in 3D.",
5
5
  "keywords": [
6
6
  "3d",
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "files": [
22
22
  "paseo-plugin.json",
23
+ "OVERVIEW.md",
23
24
  "icon.png",
24
25
  "index.client.tsx",
25
26
  "index.server.ts",
@@ -2,6 +2,8 @@ import {
2
2
  CHECKLIST_STEP_MAX,
3
3
  CHECKLIST_TEXT_MAX,
4
4
  type ChecklistStep,
5
+ type ChecklistCounts,
6
+ type ChecklistProgress,
5
7
  type Checklists,
6
8
  } from "../shared/contracts.js";
7
9
  import type { ActivityKind, ActivityStep, TestResult } from "../shared/names.js";
@@ -248,36 +250,40 @@ export function nextStep(
248
250
  }
249
251
 
250
252
  /**
251
- * A step as the office sends it: its text's first line, cut to the most it sends. Null for a
252
- * finished step, and for one with no text to show.
253
+ * A step as the office sends it: its text's first line, cut to the most it sends. Finished steps contribute to the count only.
253
254
  */
254
- function checklistStep(entry: unknown): ChecklistStep | null {
255
+ function checklistStep(entry: unknown): ChecklistStep | "done" | null {
255
256
  const text = field(entry, "text");
256
257
  if (typeof text !== "string") return null;
257
258
  const status = field(entry, "status");
258
259
  // Either one saying finished wins: providers do not keep the pair consistent.
259
260
  const finished = field(entry, "completed") === true || status === "completed";
260
- if (finished) return null;
261
261
  const line = text.split(/[\r\n]/, 1)[0].trim();
262
262
  if (line === "") return null;
263
+ if (finished) return "done";
263
264
  const shown =
264
265
  line.length > CHECKLIST_TEXT_MAX ? `${line.slice(0, CHECKLIST_TEXT_MAX - 1)}…` : line;
265
266
  return { text: shown, status: status === "in_progress" ? "in_progress" : "pending" };
266
267
  }
267
268
 
268
269
  /** The unfinished steps of the newest todo item in a tail; null when the tail has none. */
269
- export function readChecklist(items: readonly ActivityItem[]): ChecklistStep[] | null {
270
+ export function readChecklist(items: readonly ActivityItem[]): {
271
+ steps: ChecklistStep[];
272
+ progress: ChecklistProgress;
273
+ } | null {
270
274
  const todo = items.findLast((item) => item.type === "todo");
271
275
  if (todo === undefined) return null;
272
- if (!Array.isArray(todo.items)) return [];
273
- const entries: readonly unknown[] = todo.items;
276
+ const entries: readonly unknown[] = Array.isArray(todo.items) ? todo.items : [];
277
+ const progress = { completed: 0, total: 0 };
274
278
  const steps: ChecklistStep[] = [];
275
279
  for (const entry of entries) {
276
280
  const step = checklistStep(entry);
277
- if (step !== null) steps.push(step);
278
- if (steps.length === CHECKLIST_STEP_MAX) break;
281
+ if (step === null) continue;
282
+ progress.total++;
283
+ if (step === "done") progress.completed++;
284
+ else if (steps.length < CHECKLIST_STEP_MAX) steps.push(step);
279
285
  }
280
- return steps;
286
+ return { steps, progress };
281
287
  }
282
288
 
283
289
  /** What the poller knows of each running agent: its line, and its step when it is at one. */
@@ -295,7 +301,12 @@ export interface ActivityPorts {
295
301
  * steps are finished; an agent whose read failed, or whose tail has none, is absent. An agent
296
302
  * that stopped since the last round is read for this alone, once.
297
303
  */
298
- onChange(activity: ActivityLines, doing: ActivitySteps, checklists: Readonly<Checklists>): void;
304
+ onChange(
305
+ activity: ActivityLines,
306
+ doing: ActivitySteps,
307
+ checklists: Readonly<Checklists>,
308
+ progress: Readonly<ChecklistCounts>,
309
+ ): void;
299
310
  }
300
311
 
301
312
  export interface ActivityPoller {
@@ -325,7 +336,7 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
325
336
  let cancel: (() => void) | null = null;
326
337
  let previous: ActivityLines = {};
327
338
  let previousSteps: ActivitySteps = {};
328
- let previousChecklists = "{}";
339
+ let previousChecklists = "[{},{}]";
329
340
  let wasRunning: readonly string[] = [];
330
341
  // The calls each agent's last read saw, kept while the poller runs: an agent's next turn is
331
342
  // read against them too. A prompt ends the look back, so an old turn's call is never told.
@@ -336,6 +347,7 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
336
347
  next: Record<string, string>,
337
348
  steps: Record<string, ActivityStep>,
338
349
  checklists: Checklists,
350
+ progress: ChecklistCounts,
339
351
  ): Promise<void> {
340
352
  try {
341
353
  const items = await ports.tail(agentId);
@@ -345,7 +357,10 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
345
357
  const step = nextStep(previousSteps[agentId], items, seen);
346
358
  if (step !== null) steps[agentId] = step;
347
359
  const checklist = readChecklist(items);
348
- if (checklist !== null) checklists[agentId] = checklist;
360
+ if (checklist !== null) {
361
+ checklists[agentId] = checklist.steps;
362
+ progress[agentId] = checklist.progress;
363
+ }
349
364
  const calls = callsIn(items);
350
365
  // A call held back for a run's end has not been told: it stays new for the next read.
351
366
  const newest = describeStep(items, seen);
@@ -362,10 +377,17 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
362
377
 
363
378
  // An agent often ticks its last step and stops between two reads: it is read once more after
364
379
  // it stopped, for its checklist alone. A failed read leaves the checklist it had.
365
- async function readStopped(agentId: string, checklists: Checklists): Promise<void> {
380
+ async function readStopped(
381
+ agentId: string,
382
+ checklists: Checklists,
383
+ progress: ChecklistCounts,
384
+ ): Promise<void> {
366
385
  try {
367
386
  const checklist = readChecklist(await ports.tail(agentId));
368
- if (checklist !== null) checklists[agentId] = checklist;
387
+ if (checklist !== null) {
388
+ checklists[agentId] = checklist.steps;
389
+ progress[agentId] = checklist.progress;
390
+ }
369
391
  } catch (error) {
370
392
  if (!stopped) ports.log(`[office] activity of ${agentId}: ${errorMessage(error)}`);
371
393
  }
@@ -375,17 +397,18 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
375
397
  const next: Record<string, string> = {};
376
398
  const steps: Record<string, ActivityStep> = {};
377
399
  const checklists: Checklists = {};
400
+ const progress: ChecklistCounts = {};
378
401
  const running = [...ports.running()];
379
402
  for (const agentId of running) {
380
403
  if (stopped) return;
381
- await readOne(agentId, next, steps, checklists);
404
+ await readOne(agentId, next, steps, checklists, progress);
382
405
  }
383
406
  for (const agentId of wasRunning) {
384
407
  if (stopped) return;
385
- if (!running.includes(agentId)) await readStopped(agentId, checklists);
408
+ if (!running.includes(agentId)) await readStopped(agentId, checklists, progress);
386
409
  }
387
410
  wasRunning = running;
388
- const checklistsText = JSON.stringify(checklists);
411
+ const checklistsText = JSON.stringify([checklists, progress]);
389
412
  const unchanged =
390
413
  sameLines(previous, next) &&
391
414
  sameSteps(previousSteps, steps) &&
@@ -394,7 +417,7 @@ export function startActivityPoller(ports: ActivityPorts): ActivityPoller {
394
417
  previous = next;
395
418
  previousSteps = steps;
396
419
  previousChecklists = checklistsText;
397
- ports.onChange(next, steps, checklists);
420
+ ports.onChange(next, steps, checklists, progress);
398
421
  }
399
422
 
400
423
  function runLogged(): void {