paseo-office 0.2.7 → 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.
@@ -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";
@@ -35,6 +38,7 @@ type HostSetting =
35
38
  | "Streamer mode"
36
39
  | "History vault"
37
40
  | "Pinned notes"
41
+ | "Cache clock"
38
42
  | "Sticky notes"
39
43
  | "Notes folder"
40
44
  | "Time zone"
@@ -434,6 +438,12 @@ function TrackerFields({ values, incidents, change, saveProblem, styles }: Track
434
438
  );
435
439
  }
436
440
 
441
+ const CACHE_CLOCK_NAMES: Readonly<Record<CacheClock, string>> = {
442
+ off: "No cup",
443
+ "5m": "5 minutes",
444
+ "1h": "1 hour",
445
+ };
446
+
437
447
  /** The floor's own: what bubbles may name, and the owner's notes on the whiteboard. */
438
448
  function FloorSettings({
439
449
  values: stored,
@@ -455,6 +465,11 @@ function FloorSettings({
455
465
  [change],
456
466
  );
457
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");
458
473
  return (
459
474
  <View style={settingsLayout.block}>
460
475
  {stored && (
@@ -492,6 +507,36 @@ function FloorSettings({
492
507
  {vaultProblem}
493
508
  </Text>
494
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>
495
540
  <SettingField
496
541
  label="Sticky notes"
497
542
  hint={`Your notes on the 3D whiteboard, with ; between them. Up to ${STICKY_NOTES_MAX}, ${STICKY_NOTE_MAX} characters each.`}
@@ -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}
@@ -2293,6 +2293,7 @@ export function OfficeSurface(
2293
2293
  />
2294
2294
  <MachineCard
2295
2295
  workspaces={office.state.workspaces}
2296
+ agents={office.state.agents}
2296
2297
  ssh={ssh}
2297
2298
  machine={machine}
2298
2299
  open={machineOpen}
@@ -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
  }
@@ -1,4 +1,5 @@
1
1
  import type { PlanUsage } from "../../shared/plan-usage.js";
2
+ import type { CacheClock } from "../../shared/settings.js";
2
3
  import { shirtColor } from "../../shared/appearance.js";
3
4
  import type { OfficeBrand } from "../brand.js";
4
5
  import {
@@ -73,6 +74,7 @@ function subId(parentId: string, callId: string): string {
73
74
  }
74
75
 
75
76
  const NOBODY_OUT: ReadonlyMap<string, string> = new Map();
77
+ const CACHE_MS = { "5m": 5 * 60_000, "1h": 60 * 60_000 } as const;
76
78
 
77
79
  /** The plans as the scene reads them: a name and how much of each limit is used. */
78
80
  export function worldLimits(usage: readonly PlanUsage[]): WorldLimit[] {
@@ -85,12 +87,35 @@ export function worldLimits(usage: readonly PlanUsage[]): WorldLimit[] {
85
87
  }));
86
88
  }
87
89
 
90
+ /**
91
+ * A resting person's prompt cache, guessed: warm for the setting's time after the turn's end.
92
+ * Nothing for whoever is not resting, when the setting is off, or when the host did not say when
93
+ * the turn ended.
94
+ */
95
+ function cacheOf(
96
+ agent: OfficeAgent,
97
+ resting: boolean,
98
+ idle: number,
99
+ cacheClock: CacheClock,
100
+ ): Pick<WorldSession, "cache"> {
101
+ if (!resting || cacheClock === "off" || !Number.isFinite(idle)) return {};
102
+ return {
103
+ cache: {
104
+ until: idle + CACHE_MS[cacheClock],
105
+ ttl: cacheClock,
106
+ tokens: agent.context?.usedTokens ?? 0,
107
+ guessed: true,
108
+ },
109
+ };
110
+ }
111
+
88
112
  function toSession(
89
113
  row: OfficeRow,
90
114
  team: string,
91
115
  checks: WorkspacePullRequest["checks"] | undefined,
92
116
  born: Readonly<Record<string, string>>,
93
117
  out: ReadonlyMap<string, string>,
118
+ cacheClock: CacheClock,
94
119
  ): WorldSession {
95
120
  const { agent } = row;
96
121
  const title = agentTitle(agent);
@@ -119,6 +144,7 @@ function toSession(
119
144
  ? { doneAt: idle, idleSince: agent.idleSince }
120
145
  : {}),
121
146
  stuck,
147
+ ...cacheOf(agent, status === "rest" && !stuck, idle, cacheClock),
122
148
  ...(row.waitingOn > 0 ? { waitingOn: row.waitingOn } : {}),
123
149
  subs: (row.subagents ?? []).map((sub) => ({ id: subId(agent.id, sub.id), type: sub.type })),
124
150
  ...(agent.context === undefined && agent.costUsd === undefined
@@ -142,11 +168,14 @@ export function worldPeople(
142
168
  desks: number,
143
169
  born: Readonly<Record<string, string>> = {},
144
170
  out: ReadonlyMap<string, string> = NOBODY_OUT,
171
+ cacheClock: CacheClock = "off",
145
172
  ): WorldPeople {
146
173
  const rows = model.rooms.flatMap((room) =>
147
174
  room.rows.map((row) => ({ row, team: room.name, checks: room.workspace?.pullRequest?.checks })),
148
175
  );
149
- const all = rows.map(({ row, team, checks }) => toSession(row, team, checks, born, out));
176
+ const all = rows.map(({ row, team, checks }) =>
177
+ toSession(row, team, checks, born, out, cacheClock),
178
+ );
150
179
  const order = new Map(all.map((session, index) => [session.id, index]));
151
180
  const seated =
152
181
  all.length <= desks
@@ -103,9 +103,13 @@ export function useWorldFeed(
103
103
  // Whose plan is used up is named on their session, so the scene knows who takes the break.
104
104
  const usage = usePlanUsageValue();
105
105
  const out = useMemo(() => providersOut(usage, Date.now()), [usage]);
106
+ // The host's settings: the cache clock here, streamer mode and the sticky notes below.
107
+ const host = useSettings(officeHostSettings);
108
+ const hostValues = host.status === "ready" ? host.values : null;
109
+ const cacheClock = hostValues?.cacheClock ?? "off";
106
110
  const people = useMemo(
107
- () => worldPeople(model, PLAN_DESKS[plan], life?.born, out),
108
- [model, plan, life?.born, out],
111
+ () => worldPeople(model, PLAN_DESKS[plan], life?.born, out, cacheClock),
112
+ [model, plan, life?.born, out, cacheClock],
109
113
  );
110
114
  useEffect(() => {
111
115
  const scene = world.current;
@@ -128,8 +132,6 @@ export function useWorldFeed(
128
132
  }, [worldReadings, api]);
129
133
 
130
134
  // The host's: whether bubbles name what a person is at, and the owner's notes on the whiteboard.
131
- const host = useSettings(officeHostSettings);
132
- const hostValues = host.status === "ready" ? host.values : null;
133
135
  const streamer = hostValues?.streamerMode ?? null;
134
136
  const notesText = hostValues?.stickyNotes ?? null;
135
137
  useEffect(() => {
@@ -30,6 +30,8 @@ export interface WorldSession {
30
30
  git: { repo: string; ci?: "red" | "green"; born?: string };
31
31
  /** At work, waiting for the user's answer, or resting. */
32
32
  status: "work" | "wait" | "rest";
33
+ /** The prompt cache's clock, guessed from the turn's end: the cup on a resting desk steams until `until` (epoch ms). */
34
+ cache?: { until: number; ttl: "5m" | "1h"; tokens: number; guessed: true };
33
35
  /** The plan the person runs on, only while that plan is used up: named on their tag, and they take a break. */
34
36
  acct?: string;
35
37
  /** Which mark the scene puts on the person's screen. */
package/docs/office.md CHANGED
@@ -546,6 +546,25 @@ start a turn.
546
546
  Not done here: blocking a call before it runs and undoing a turn's edits. Both need real Claude
547
547
  Code hooks written into the host's `~/.claude/settings.json`.
548
548
 
549
+ ## Plan and machine tools
550
+
551
+ - **What eats your plan.** Under This week in the Timeline card: the five agents that used the
552
+ most in the last seven days, by cost where their provider reports one and by time at work
553
+ otherwise. It is as detailed as what Paseo reports per agent, and counts what the office saw.
554
+ - **Forgotten work.** In the Host card, **Check** looks in each workspace's folder, and in the
555
+ other worktrees of its repository, for files not committed, commits no remote has, and stashes
556
+ (`office.forgotten.request`, `server/forgotten-work.ts`). It answers with counts only. It runs
557
+ git, so it reads when asked, not on a timer.
558
+ - **Models.** The Host card lists each agent that has sub-agents with its model and the models
559
+ they run on. A provider's own sub-agents (Claude's Agent tool) are not Paseo agents and have no
560
+ model the office can read.
561
+ - **The cache clock.** On the 3D floor a resting desk has a cup that steams while the session's
562
+ prompt cache is taken to be warm, and stands cold after. Paseo does not report the cache, so
563
+ it is an estimate from the end of the last turn: an hour by default, five minutes or no cup in
564
+ Settings.
565
+ - **Accounts.** The Host card's plan limits are per provider. Switching accounts is the
566
+ `account-switcher` plugin's; the office handles no sign-in.
567
+
549
568
  ## History vault and the prompt report
550
569
 
551
570
  **History vault** (Settings, host-wide, off by default) has the office keep what is said in each
package/index.server.ts CHANGED
@@ -48,6 +48,7 @@ import { projectPlanUsage } from "./server/plan-usage.js";
48
48
  import { promptReport } from "./shared/vault.js";
49
49
  import { pinnedNote } from "./shared/alerts.js";
50
50
  import { createWatchers } from "./server/watchers.js";
51
+ import { readForgotten, type Checkout } from "./server/forgotten-work.js";
51
52
  import {
52
53
  VAULT_TAIL_LIMIT,
53
54
  VaultFileSchema,
@@ -132,6 +133,7 @@ import {
132
133
  timelineRpc,
133
134
  alertDismissRpc,
134
135
  alertsRpc,
136
+ forgottenRpc,
135
137
  vaultReportRpc,
136
138
  vaultSearchRpc,
137
139
  vaultTalkRpc,
@@ -301,6 +303,14 @@ export function createOfficePlugin(
301
303
  stopVault = hub.watch(vault.view);
302
304
  })().catch((error: unknown) => log(`[office] history vault unavailable: ${errorMessage(error)}`));
303
305
  const stopWatchers = hub.watch(watchers.view);
306
+ // The workspaces' folders as the directory last reported them, for the forgotten-work read.
307
+ let checkouts: Checkout[] = [];
308
+ const stopCheckouts = hub.watch((view) => {
309
+ checkouts = (view?.workspaces ?? []).flatMap((workspace) => {
310
+ const folder = view?.folders?.[workspace.id];
311
+ return folder ? [{ workspaceId: workspace.id, name: workspace.name, folder }] : [];
312
+ });
313
+ });
304
314
  let stopTimeline: (() => void) | undefined;
305
315
  const timelineReady = (async () => {
306
316
  const kept = (await deps.timelineFile?.load()) ?? null;
@@ -767,6 +777,9 @@ export function createOfficePlugin(
767
777
  const start = Math.max(from, end - TIMELINE_KEEP_MS);
768
778
  return { ok: true as const, timeline: timeline.read(start, end) };
769
779
  });
780
+ server.handle(forgottenRpc, async () => ({
781
+ items: await readForgotten(checkouts, execCommand),
782
+ }));
770
783
  server.handle(alertsRpc, async () => ({ alerts: watchers.alerts() }));
771
784
  server.handle(alertDismissRpc, async ({ id }) => {
772
785
  watchers.dismiss(id);
@@ -1004,6 +1017,7 @@ export function createOfficePlugin(
1004
1017
  stopLife?.();
1005
1018
  stopTimeline?.();
1006
1019
  stopWatchers();
1020
+ stopCheckouts();
1007
1021
  stopVault?.();
1008
1022
  await vaultSaves?.flush();
1009
1023
  await timelineSaves?.flush();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paseo-office",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "A community port of my-office for Paseo: your agents at their desks, in 3D.",
5
5
  "keywords": [
6
6
  "3d",
@@ -0,0 +1,104 @@
1
+ import type { Forgotten } from "../shared/forgotten.js";
2
+ import type { Exec } from "./repo-age.js";
3
+
4
+ /** The most checkouts looked at in one read. */
5
+ export const FORGOTTEN_MAX = 40;
6
+
7
+ export interface Checkout {
8
+ workspaceId: string | null;
9
+ name: string;
10
+ folder: string;
11
+ }
12
+
13
+ function lines(text: string): string[] {
14
+ return text.split("\n").filter((line) => line.trim() !== "");
15
+ }
16
+
17
+ /** The lines `git` prints for these arguments in a folder; null when git cannot say. */
18
+ async function git(exec: Exec, folder: string, args: string[]): Promise<string[] | null> {
19
+ try {
20
+ const { stdout } = await exec("git", args, {
21
+ cwd: folder,
22
+ timeout: 10_000,
23
+ maxBuffer: 1 << 22,
24
+ // Reading must not take a lock an agent's own git is waiting for.
25
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
26
+ });
27
+ return lines(stdout);
28
+ } catch {
29
+ return null;
30
+ }
31
+ }
32
+
33
+ /** A repository's other worktrees: the folders `git worktree list` names besides the ones given. */
34
+ async function otherWorktrees(
35
+ exec: Exec,
36
+ folder: string,
37
+ known: ReadonlySet<string>,
38
+ ): Promise<string[]> {
39
+ const listed = await git(exec, folder, ["worktree", "list", "--porcelain"]);
40
+ if (listed === null) return [];
41
+ return listed
42
+ .filter((line) => line.startsWith("worktree "))
43
+ .map((line) => line.slice("worktree ".length))
44
+ .filter((path) => !known.has(path));
45
+ }
46
+
47
+ async function readCheckout(exec: Exec, checkout: Checkout): Promise<Forgotten | null> {
48
+ const changed = await git(exec, checkout.folder, ["status", "--porcelain"]);
49
+ // Not a repository, or one git cannot read: nothing to say of it.
50
+ if (changed === null) return null;
51
+ // Commits no remote has: also the ones of a branch that was never pushed.
52
+ const unpushed = await git(exec, checkout.folder, [
53
+ "log",
54
+ "--oneline",
55
+ "HEAD",
56
+ "--not",
57
+ "--remotes",
58
+ ]);
59
+ const stashes = await git(exec, checkout.folder, ["stash", "list"]);
60
+ const found = {
61
+ name: checkout.name,
62
+ workspaceId: checkout.workspaceId,
63
+ changed: changed.length,
64
+ unpushed: unpushed?.length ?? 0,
65
+ stashes: stashes?.length ?? 0,
66
+ };
67
+ return found.changed + found.unpushed + found.stashes === 0 ? null : found;
68
+ }
69
+
70
+ /**
71
+ * The checkouts with unfinished work: each workspace's folder, and the worktrees of their
72
+ * repositories that no workspace has. Counts only: no file name, branch or message is read out.
73
+ * A stash belongs to the repository, so every worktree of it reports the same stashes; they are
74
+ * counted on the first.
75
+ */
76
+ export async function readForgotten(
77
+ workspaces: readonly Checkout[],
78
+ exec: Exec,
79
+ ): Promise<Forgotten[]> {
80
+ const known = new Set(workspaces.map((workspace) => workspace.folder));
81
+ const checkouts: Checkout[] = workspaces.slice(0, FORGOTTEN_MAX);
82
+ for (const workspace of workspaces) {
83
+ if (checkouts.length >= FORGOTTEN_MAX) break;
84
+ for (const path of await otherWorktrees(exec, workspace.folder, known)) {
85
+ known.add(path);
86
+ const name = path.split(/[\\/]/).at(-1) ?? path;
87
+ checkouts.push({ workspaceId: null, name, folder: path });
88
+ }
89
+ }
90
+ const stashed = new Set<string>();
91
+ const found: Forgotten[] = [];
92
+ for (const checkout of checkouts.slice(0, FORGOTTEN_MAX)) {
93
+ const item = await readCheckout(exec, checkout);
94
+ if (item === null) continue;
95
+ if (item.stashes > 0) {
96
+ const common = await git(exec, checkout.folder, ["rev-parse", "--git-common-dir"]);
97
+ const repo = common?.[0] ?? checkout.folder;
98
+ if (stashed.has(repo)) item.stashes = 0;
99
+ stashed.add(repo);
100
+ }
101
+ if (item.changed + item.unpushed + item.stashes > 0) found.push(item);
102
+ }
103
+ return found;
104
+ }
@@ -5,6 +5,7 @@ import { defineRpc, defineSubscription } from "@getpaseo/plugin";
5
5
  import { PlanUsageSchema } from "./plan-usage.js";
6
6
  import { TimelineSchema } from "./timeline.js";
7
7
  import { AlertSchema } from "./alerts.js";
8
+ import { ForgottenSchema } from "./forgotten.js";
8
9
  import { PromptReportSchema, VaultHitSchema, VaultTalkSchema } from "./vault.js";
9
10
  import { z } from "zod";
10
11
  // In their own file, so code that needs only a name does not load the schemas.
@@ -837,6 +838,16 @@ export const vaultReportRpc = defineRpc({
837
838
  output: z.object({ on: z.boolean(), report: PromptReportSchema }),
838
839
  });
839
840
 
841
+ /**
842
+ * The checkouts with unfinished work, by their counts. It runs git in each workspace's folder, so
843
+ * it is read when the owner asks.
844
+ */
845
+ export const forgottenRpc = defineRpc({
846
+ name: "office.forgotten.request",
847
+ input: z.object({}),
848
+ output: z.object({ items: z.array(ForgottenSchema) }),
849
+ });
850
+
840
851
  /** What the office noticed and nobody dismissed, newest first. */
841
852
  export const alertsRpc = defineRpc({
842
853
  name: "office.alerts.request",
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ import type { OfficeAgent } from "./contracts.js";
3
+ import { agentTitle } from "./model.js";
4
+
5
+ /** A checkout with work nobody has finished: files not committed, commits on no remote, a stash. */
6
+ export const ForgottenSchema = z.object({
7
+ /** The team's name, or the folder's for a worktree no workspace has. */
8
+ name: z.string(),
9
+ /** Null for a worktree no workspace has. */
10
+ workspaceId: z.string().nullable(),
11
+ changed: z.number(),
12
+ unpushed: z.number(),
13
+ stashes: z.number(),
14
+ });
15
+ export type Forgotten = z.output<typeof ForgottenSchema>;
16
+
17
+ function count(n: number, one: string, many: string): string | null {
18
+ if (n === 0) return null;
19
+ return `${n} ${n === 1 ? one : many}`;
20
+ }
21
+
22
+ /** "3 changed files, 2 unpushed commits, 1 stash". */
23
+ export function forgottenText(item: Forgotten): string {
24
+ return [
25
+ count(item.changed, "changed file", "changed files"),
26
+ count(item.unpushed, "unpushed commit", "unpushed commits"),
27
+ count(item.stashes, "stash", "stashes"),
28
+ ]
29
+ .filter((part) => part !== null)
30
+ .join(", ");
31
+ }
32
+
33
+ export interface CoordinatorModels {
34
+ id: string;
35
+ name: string;
36
+ /** Null when its provider names no model. */
37
+ model: string | null;
38
+ /** Its sub-agents by model, the most used first. */
39
+ subs: { model: string; count: number }[];
40
+ }
41
+
42
+ /** Each agent that has sub-agents, with its model and the models they run on. */
43
+ export function coordinatorModels(agents: readonly OfficeAgent[]): CoordinatorModels[] {
44
+ const byParent = new Map<string, Map<string, number>>();
45
+ for (const agent of agents) {
46
+ if (agent.parentAgentId === null || agent.status === "closed") continue;
47
+ const models = byParent.get(agent.parentAgentId) ?? new Map<string, number>();
48
+ const model = agent.model ?? "an unnamed model";
49
+ models.set(model, (models.get(model) ?? 0) + 1);
50
+ byParent.set(agent.parentAgentId, models);
51
+ }
52
+ const coordinators: CoordinatorModels[] = [];
53
+ for (const agent of agents) {
54
+ const models = byParent.get(agent.id);
55
+ if (models === undefined) continue;
56
+ coordinators.push({
57
+ id: agent.id,
58
+ name: agentTitle(agent),
59
+ model: agent.model,
60
+ subs: [...models]
61
+ .map(([model, n]) => ({ model, count: n }))
62
+ .sort((a, b) => b.count - a.count || a.model.localeCompare(b.model)),
63
+ });
64
+ }
65
+ return coordinators;
66
+ }
67
+
68
+ /** "2 on sonnet, 1 on haiku". */
69
+ export function subModelsText(subs: CoordinatorModels["subs"]): string {
70
+ return subs.map((sub) => `${sub.count} on ${sub.model}`).join(", ");
71
+ }
@@ -64,6 +64,10 @@ export function stickyNotesOf(text: string): string[] {
64
64
  );
65
65
  }
66
66
 
67
+ /** How long a prompt cache is taken to stay warm after a turn, for the cup on a resting desk. */
68
+ export const CACHE_CLOCKS = ["off", "5m", "1h"] as const;
69
+ export type CacheClock = (typeof CACHE_CLOCKS)[number];
70
+
67
71
  const HostValuesSchema = z.object({
68
72
  ...brandFields,
69
73
  archiveOnDeparture: z.boolean().default(false),
@@ -80,6 +84,7 @@ const HostValuesSchema = z.object({
80
84
  streamerMode: z.boolean().default(true),
81
85
  historyVault: z.boolean().default(false),
82
86
  pinnedNotes: z.string().max(PINNED_NOTES_MAX).default(""),
87
+ cacheClock: z.enum(CACHE_CLOCKS).default("1h").catch("1h"),
83
88
  stickyNotes: z.string().max(STICKY_NOTES_TEXT_MAX).default(""),
84
89
  jiraProjects: z.string().default(""),
85
90
  sentryOrg: z.string().default(""),
@@ -149,7 +154,8 @@ const SUNDAY_TO_THURSDAY = [0, 1, 2, 3, 4];
149
154
  * owner's notes on the 3D whiteboard, with `;` between them. `historyVault` on has the office
150
155
  * keep what is said in each conversation in a file on the host; it is off until the owner turns
151
156
  * it on. `pinnedNotes` is said again to an agent whose conversation is compacted during a turn;
152
- * empty says nothing. `jiraProjects`
157
+ * empty says nothing. `cacheClock` is how long a prompt cache is taken to last after a turn, for
158
+ * the steaming cup on a resting desk of the 3D floor; `off` draws none. `jiraProjects`
153
159
  * and `sentryProjects` are the comma separated projects checked for incidents, `sentryOrg` their
154
160
  * Sentry organisation and `sentryUrl` the Sentry the token is sent to.
155
161
  */
@@ -124,6 +124,33 @@ export interface WeekRecap {
124
124
  days: { from: number; workMs: number }[];
125
125
  }
126
126
 
127
+ export interface PlanEater {
128
+ id: string;
129
+ name: string;
130
+ team: string;
131
+ workMs: number;
132
+ /** Null when its provider says no cost. */
133
+ costUsd: number | null;
134
+ }
135
+
136
+ /** The lanes that used the most: by cost where a provider says one, else by time at work. */
137
+ export function planEaters(timeline: Timeline, most = 5): PlanEater[] {
138
+ return timeline.lanes
139
+ .map((lane) => ({
140
+ id: lane.id,
141
+ name: lane.name,
142
+ team: lane.team,
143
+ costUsd: lane.costUsd,
144
+ workMs: lane.spans.reduce(
145
+ (total, span) => total + (span.state === "work" ? span.to - span.from : 0),
146
+ 0,
147
+ ),
148
+ }))
149
+ .filter((eater) => eater.workMs > 0 || (eater.costUsd ?? 0) > 0)
150
+ .sort((a, b) => (b.costUsd ?? 0) - (a.costUsd ?? 0) || b.workMs - a.workMs)
151
+ .slice(0, most);
152
+ }
153
+
127
154
  function overlap(span: TimelineSpan, from: number, to: number): number {
128
155
  return Math.max(0, Math.min(span.to, to) - Math.max(span.from, from));
129
156
  }