paseo-office 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/alert-card.tsx +195 -0
- package/client/host-switches.tsx +71 -0
- package/client/host-work.tsx +97 -0
- package/client/machine-card.tsx +22 -2
- package/client/office-surface.tsx +15 -0
- package/client/timeline-card.tsx +29 -0
- package/client/use-alerts.ts +71 -0
- package/client/world/adapter.ts +30 -1
- package/client/world/use-world-feed.ts +6 -4
- package/client/world/world-api.ts +2 -0
- package/docs/office.md +49 -0
- package/index.server.ts +45 -1
- package/package.json +1 -1
- package/server/forgotten-work.ts +104 -0
- package/server/live-ports.ts +7 -0
- package/server/watchers.ts +308 -0
- package/shared/alerts.ts +48 -0
- package/shared/contracts.ts +26 -0
- package/shared/forgotten.ts +71 -0
- package/shared/settings.ts +10 -1
- package/shared/timeline.ts +27 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import type { Alert } from "../shared/alerts.js";
|
|
2
|
+
import type { OfficeAgent } from "../shared/contracts.js";
|
|
3
|
+
import { agentTitle } from "../shared/model.js";
|
|
4
|
+
import type { DirectoryView } from "./hub.js";
|
|
5
|
+
|
|
6
|
+
/** A timeline entry as the watchers read it: where it is in the timeline, and the item. */
|
|
7
|
+
export interface WatchedEntry {
|
|
8
|
+
seq: number;
|
|
9
|
+
item: {
|
|
10
|
+
type: string;
|
|
11
|
+
status?: unknown;
|
|
12
|
+
name?: unknown;
|
|
13
|
+
callId?: unknown;
|
|
14
|
+
detail?: unknown;
|
|
15
|
+
error?: unknown;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface WatcherPorts {
|
|
20
|
+
now(): number;
|
|
21
|
+
/** Whether alerts may name a file or a command: the host's streamer mode is off. */
|
|
22
|
+
named(): boolean;
|
|
23
|
+
/** The owner's pinned notes; empty for none. */
|
|
24
|
+
pinnedNotes(): string;
|
|
25
|
+
/** Says the pinned notes to an agent whose conversation was compacted mid-turn. */
|
|
26
|
+
remind(agentId: string, notes: string): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Watchers {
|
|
30
|
+
/** The office as the directory reports it; null when the office stops watching. */
|
|
31
|
+
view(view: DirectoryView | null): void;
|
|
32
|
+
/** The newest entries of a running agent's timeline, oldest first, as each activity read sees them. */
|
|
33
|
+
tail(agentId: string, entries: readonly WatchedEntry[]): void;
|
|
34
|
+
alerts(): Alert[];
|
|
35
|
+
dismiss(id: string): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The same failing call this many times running is a loop. */
|
|
39
|
+
export const LOOP_CALLS = 3;
|
|
40
|
+
/** Two agents changing one file within this long is a clash; a clash and a refusal are shown this long. */
|
|
41
|
+
export const CLASH_WINDOW_MS = 10 * 60_000;
|
|
42
|
+
export const ALERT_TTL_MS = 30 * 60_000;
|
|
43
|
+
const CALLS_KEPT = 30;
|
|
44
|
+
const DETAIL_MAX = 200;
|
|
45
|
+
|
|
46
|
+
const REFUSED = /auto mode classifier|denied by the .{0,40}classifier/i;
|
|
47
|
+
const PORT_TAKEN = /EADDRINUSE|address already in use/i;
|
|
48
|
+
|
|
49
|
+
interface Call {
|
|
50
|
+
id: string;
|
|
51
|
+
sig: string;
|
|
52
|
+
tool: string;
|
|
53
|
+
label: string;
|
|
54
|
+
file: string | null;
|
|
55
|
+
status: string;
|
|
56
|
+
error: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function field(value: unknown, key: string): unknown {
|
|
60
|
+
return typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function text(value: unknown): string {
|
|
64
|
+
if (typeof value === "string") return value;
|
|
65
|
+
if (value === null || value === undefined) return "";
|
|
66
|
+
const message = field(value, "message");
|
|
67
|
+
if (typeof message === "string") return message;
|
|
68
|
+
try {
|
|
69
|
+
return JSON.stringify(value) ?? "";
|
|
70
|
+
} catch {
|
|
71
|
+
return "";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function cut(value: string, max = DETAIL_MAX): string {
|
|
76
|
+
const line = value.replace(/\s+/g, " ").trim();
|
|
77
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function baseName(path: string): string {
|
|
81
|
+
return path.split(/[\\/]/).at(-1) ?? path;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function callOf(item: WatchedEntry["item"]): Call | null {
|
|
85
|
+
if (item.type !== "tool_call" || typeof item.callId !== "string" || item.callId === "") {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const tool = typeof item.name === "string" ? cut(item.name, 40) : "a tool";
|
|
89
|
+
const command = field(item.detail, "command");
|
|
90
|
+
const filePath = field(item.detail, "filePath");
|
|
91
|
+
const isEdit = ["edit", "write"].includes(String(field(item.detail, "type")));
|
|
92
|
+
let label = "";
|
|
93
|
+
if (typeof command === "string") label = cut(command, 80);
|
|
94
|
+
else if (typeof filePath === "string") label = baseName(filePath);
|
|
95
|
+
return {
|
|
96
|
+
id: item.callId,
|
|
97
|
+
// What makes two calls the same call: the tool and what it was given.
|
|
98
|
+
sig: `${tool}\n${text(item.detail)}`,
|
|
99
|
+
tool,
|
|
100
|
+
label,
|
|
101
|
+
file: isEdit && typeof filePath === "string" ? filePath : null,
|
|
102
|
+
status: typeof item.status === "string" ? item.status : "",
|
|
103
|
+
error: text(item.error),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface Watched {
|
|
108
|
+
calls: Call[];
|
|
109
|
+
/** The last timeline sequence number read: a compaction after it is new. */
|
|
110
|
+
seq: number;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface Edit {
|
|
114
|
+
agentId: string;
|
|
115
|
+
at: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Notices what Claude Code's hooks would: a loop of failing calls, a call auto mode refused, two
|
|
120
|
+
* agents in one file, a taken port, failing checks. It reads what the office reads anyway (each
|
|
121
|
+
* running agent's newest timeline entries every 5 s, and the directory), so it notices only while
|
|
122
|
+
* an office is open, and for every provider.
|
|
123
|
+
*/
|
|
124
|
+
export function createWatchers(ports: WatcherPorts): Watchers {
|
|
125
|
+
const watched = new Map<string, Watched>();
|
|
126
|
+
const names = new Map<string, string>();
|
|
127
|
+
const edits = new Map<string, Edit[]>();
|
|
128
|
+
const alerts = new Map<string, Alert>();
|
|
129
|
+
const dismissed = new Set<string>();
|
|
130
|
+
|
|
131
|
+
function raise(alert: Omit<Alert, "at">): void {
|
|
132
|
+
if (alerts.has(alert.id) || dismissed.has(alert.id)) return;
|
|
133
|
+
alerts.set(alert.id, { ...alert, at: ports.now() });
|
|
134
|
+
}
|
|
135
|
+
const nameOf = (agentId: string) => names.get(agentId) ?? "An agent";
|
|
136
|
+
const what = (call: Call) => (ports.named() && call.label !== "" ? call.label : call.tool);
|
|
137
|
+
|
|
138
|
+
function noticeLoop(agentId: string, calls: readonly Call[]): void {
|
|
139
|
+
const ended = calls.filter((call) => call.status !== "running");
|
|
140
|
+
const last = ended.slice(-LOOP_CALLS);
|
|
141
|
+
const [first] = last;
|
|
142
|
+
const looping =
|
|
143
|
+
last.length === LOOP_CALLS &&
|
|
144
|
+
first !== undefined &&
|
|
145
|
+
last.every((call) => call.status === "failed" && call.sig === first.sig);
|
|
146
|
+
const id = `loop:${agentId}`;
|
|
147
|
+
if (!looping || first === undefined) {
|
|
148
|
+
// It got past it, or tried something else: the loop is over, and a new one is a new alert.
|
|
149
|
+
alerts.delete(id);
|
|
150
|
+
dismissed.delete(id);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
raise({
|
|
154
|
+
id,
|
|
155
|
+
kind: "loop",
|
|
156
|
+
agentId,
|
|
157
|
+
title: `${nameOf(agentId)} is stuck in a loop`,
|
|
158
|
+
detail: cut(`${what(first)} failed ${LOOP_CALLS} times running: ${first.error}`),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function noticeFailure(agentId: string, call: Call): void {
|
|
163
|
+
if (call.status !== "failed") return;
|
|
164
|
+
if (REFUSED.test(call.error)) {
|
|
165
|
+
const reason = /Reason:\s*(.+?)(?:\. If you|$)/s.exec(call.error)?.[1] ?? call.error;
|
|
166
|
+
raise({
|
|
167
|
+
id: `refused:${agentId}:${call.id}`,
|
|
168
|
+
kind: "refused",
|
|
169
|
+
agentId,
|
|
170
|
+
title: `Auto mode refused a call of ${nameOf(agentId)}`,
|
|
171
|
+
detail: cut(`${what(call)}: ${reason}`),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const port = PORT_TAKEN.test(call.error) ? /(?::|port\s+)(\d{2,5})\b/i.exec(call.error) : null;
|
|
175
|
+
if (port?.[1] !== undefined) {
|
|
176
|
+
raise({
|
|
177
|
+
id: `port:${agentId}:${port[1]}`,
|
|
178
|
+
kind: "port",
|
|
179
|
+
agentId,
|
|
180
|
+
port: Number(port[1]),
|
|
181
|
+
title: `${nameOf(agentId)} wants port ${port[1]}, which is taken`,
|
|
182
|
+
detail: cut(what(call)),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function noticeEdit(agentId: string, file: string): void {
|
|
188
|
+
const now = ports.now();
|
|
189
|
+
const recent = (edits.get(file) ?? []).filter((edit) => now - edit.at < CLASH_WINDOW_MS);
|
|
190
|
+
const other = recent.find((edit) => edit.agentId !== agentId);
|
|
191
|
+
edits.set(file, [...recent.filter((edit) => edit.agentId !== agentId), { agentId, at: now }]);
|
|
192
|
+
if (other === undefined) return;
|
|
193
|
+
const [a, b] = [agentId, other.agentId].sort();
|
|
194
|
+
const shown = ports.named() ? baseName(file) : "the same file";
|
|
195
|
+
raise({
|
|
196
|
+
id: `clash:${a}:${b}:${file}`,
|
|
197
|
+
kind: "clash",
|
|
198
|
+
agentId,
|
|
199
|
+
otherAgentId: other.agentId,
|
|
200
|
+
title: `${nameOf(agentId)} and ${nameOf(other.agentId)} are in ${shown}`,
|
|
201
|
+
detail: `Both changed ${shown} within ${CLASH_WINDOW_MS / 60_000} minutes.`,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function noticeChecks(view: DirectoryView): void {
|
|
206
|
+
const failing = new Set<string>();
|
|
207
|
+
for (const workspace of view.workspaces) {
|
|
208
|
+
const request = workspace.pullRequest;
|
|
209
|
+
if (request?.checks !== "failure") continue;
|
|
210
|
+
const id = `checks:${workspace.id}`;
|
|
211
|
+
failing.add(id);
|
|
212
|
+
const fixer = view.agents.find(
|
|
213
|
+
(agent) => agent.workspaceId === workspace.id && agent.status === "idle",
|
|
214
|
+
);
|
|
215
|
+
const runs = request.runs.filter((run) => run.status === "failure");
|
|
216
|
+
const kept = alerts.get(id);
|
|
217
|
+
// The agent that could fix them changes as agents start and stop: the alert follows.
|
|
218
|
+
if (kept !== undefined) {
|
|
219
|
+
const { agentId: _before, ...rest } = kept;
|
|
220
|
+
alerts.set(id, fixer ? { ...rest, agentId: fixer.id } : rest);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
raise({
|
|
224
|
+
id,
|
|
225
|
+
kind: "checks",
|
|
226
|
+
workspaceId: workspace.id,
|
|
227
|
+
...(fixer ? { agentId: fixer.id } : {}),
|
|
228
|
+
title: `${workspace.name}: the checks fail`,
|
|
229
|
+
detail: cut(runs.map((run) => run.name).join(", ")),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
for (const id of alerts.keys()) {
|
|
233
|
+
if (!id.startsWith("checks:") || failing.has(id)) continue;
|
|
234
|
+
alerts.delete(id);
|
|
235
|
+
dismissed.delete(id);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function forget(gone: (agent: string) => boolean): void {
|
|
240
|
+
for (const [id, alert] of alerts) {
|
|
241
|
+
if (alert.kind !== "checks" && alert.agentId !== undefined && gone(alert.agentId)) {
|
|
242
|
+
alerts.delete(id);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function seeAgents(agents: readonly OfficeAgent[]): void {
|
|
248
|
+
const here = new Set(agents.map((agent) => agent.id));
|
|
249
|
+
for (const agent of agents) names.set(agent.id, agentTitle(agent));
|
|
250
|
+
for (const id of watched.keys()) if (!here.has(id)) watched.delete(id);
|
|
251
|
+
for (const id of names.keys()) if (!here.has(id)) names.delete(id);
|
|
252
|
+
forget((id) => !here.has(id));
|
|
253
|
+
// A turn that ended is past its loop.
|
|
254
|
+
for (const agent of agents) {
|
|
255
|
+
if (agent.status === "idle") alerts.delete(`loop:${agent.id}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return {
|
|
260
|
+
view(view) {
|
|
261
|
+
if (view === null) {
|
|
262
|
+
watched.clear();
|
|
263
|
+
edits.clear();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
seeAgents(view.agents);
|
|
267
|
+
noticeChecks(view);
|
|
268
|
+
},
|
|
269
|
+
tail(agentId, entries) {
|
|
270
|
+
const state = watched.get(agentId) ?? { calls: [], seq: -1 };
|
|
271
|
+
const first = !watched.has(agentId);
|
|
272
|
+
watched.set(agentId, state);
|
|
273
|
+
let compacted = false;
|
|
274
|
+
for (const entry of entries) {
|
|
275
|
+
const fresh = entry.seq > state.seq;
|
|
276
|
+
if (fresh && entry.item.type === "compaction" && entry.item.status === "completed") {
|
|
277
|
+
compacted = true;
|
|
278
|
+
}
|
|
279
|
+
const call = callOf(entry.item);
|
|
280
|
+
if (call === null) continue;
|
|
281
|
+
const known = state.calls.findIndex((kept) => kept.id === call.id);
|
|
282
|
+
const changed = known === -1 || state.calls[known]?.status !== call.status;
|
|
283
|
+
if (known === -1) state.calls.push(call);
|
|
284
|
+
else state.calls[known] = call;
|
|
285
|
+
// What the first read finds was there before the office looked: it is not news.
|
|
286
|
+
if (first || !changed) continue;
|
|
287
|
+
noticeFailure(agentId, call);
|
|
288
|
+
if (call.file !== null && call.status !== "failed") noticeEdit(agentId, call.file);
|
|
289
|
+
}
|
|
290
|
+
state.seq = Math.max(state.seq, ...entries.map((entry) => entry.seq));
|
|
291
|
+
state.calls = state.calls.slice(-CALLS_KEPT);
|
|
292
|
+
noticeLoop(agentId, state.calls);
|
|
293
|
+
const notes = ports.pinnedNotes().trim();
|
|
294
|
+
if (compacted && !first && notes !== "") ports.remind(agentId, notes);
|
|
295
|
+
},
|
|
296
|
+
alerts() {
|
|
297
|
+
const now = ports.now();
|
|
298
|
+
for (const [id, alert] of alerts) {
|
|
299
|
+
const passing = alert.kind === "refused" || alert.kind === "clash" || alert.kind === "port";
|
|
300
|
+
if (passing && now - alert.at > ALERT_TTL_MS) alerts.delete(id);
|
|
301
|
+
}
|
|
302
|
+
return [...alerts.values()].sort((a, b) => b.at - a.at);
|
|
303
|
+
},
|
|
304
|
+
dismiss(id) {
|
|
305
|
+
if (alerts.delete(id)) dismissed.add(id);
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
package/shared/alerts.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What the office noticed and the owner may want to act on:
|
|
5
|
+
* - `loop`: an agent made the same failing call three times running;
|
|
6
|
+
* - `refused`: the provider's auto mode refused a call;
|
|
7
|
+
* - `clash`: two agents changed the same file within a few minutes;
|
|
8
|
+
* - `port`: a command failed because its port is taken;
|
|
9
|
+
* - `checks`: the checks of a workspace's pull request fail.
|
|
10
|
+
*/
|
|
11
|
+
export const ALERT_KINDS = ["loop", "refused", "clash", "port", "checks"] as const;
|
|
12
|
+
export type AlertKind = (typeof ALERT_KINDS)[number];
|
|
13
|
+
|
|
14
|
+
export const AlertSchema = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
kind: z.enum(ALERT_KINDS),
|
|
17
|
+
/** Epoch ms it was first noticed. */
|
|
18
|
+
at: z.number(),
|
|
19
|
+
/** Whom it is about; for `checks`, an agent of the workspace that rests and could fix them. */
|
|
20
|
+
agentId: z.string().optional(),
|
|
21
|
+
/** `clash`: the other agent. */
|
|
22
|
+
otherAgentId: z.string().optional(),
|
|
23
|
+
workspaceId: z.string().optional(),
|
|
24
|
+
/** `port`: the port that is taken. */
|
|
25
|
+
port: z.number().optional(),
|
|
26
|
+
title: z.string(),
|
|
27
|
+
detail: z.string(),
|
|
28
|
+
});
|
|
29
|
+
export type Alert = z.output<typeof AlertSchema>;
|
|
30
|
+
|
|
31
|
+
/** The most characters of a pinned note, and of a hint sent from an alert. */
|
|
32
|
+
export const PINNED_NOTES_MAX = 1000;
|
|
33
|
+
export const HINT_MAX = 500;
|
|
34
|
+
|
|
35
|
+
/** What "Tell both", "Tell the agent" and "Fix it" send. One line each: an agent reads it mid-turn. */
|
|
36
|
+
export function clashNote(file: string, other: string): string {
|
|
37
|
+
return `Office notice: another session (${other}) changed ${file} in the last few minutes. Read the file again before you change it, and do not undo that session's work.`;
|
|
38
|
+
}
|
|
39
|
+
export function portNote(port: number, holder: string | null): string {
|
|
40
|
+
const who = holder === null ? "another process" : `another session's server (${holder})`;
|
|
41
|
+
return `Office notice: port ${port} is held by ${who}. Do not stop it; start yours on another port.`;
|
|
42
|
+
}
|
|
43
|
+
export function checksNote(failing: string): string {
|
|
44
|
+
return `The checks of this workspace's pull request are failing${failing === "" ? "" : ` (${failing})`}. Find out why and fix it, then say what you changed.`;
|
|
45
|
+
}
|
|
46
|
+
export function pinnedNote(notes: string): string {
|
|
47
|
+
return `Office notice: this conversation was just compacted. The owner's pinned notes still apply:\n${notes}`;
|
|
48
|
+
}
|
package/shared/contracts.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { WORDS_LANGUAGES } from "./scene-language.js";
|
|
|
4
4
|
import { defineRpc, defineSubscription } from "@getpaseo/plugin";
|
|
5
5
|
import { PlanUsageSchema } from "./plan-usage.js";
|
|
6
6
|
import { TimelineSchema } from "./timeline.js";
|
|
7
|
+
import { AlertSchema } from "./alerts.js";
|
|
8
|
+
import { ForgottenSchema } from "./forgotten.js";
|
|
7
9
|
import { PromptReportSchema, VaultHitSchema, VaultTalkSchema } from "./vault.js";
|
|
8
10
|
import { z } from "zod";
|
|
9
11
|
// In their own file, so code that needs only a name does not load the schemas.
|
|
@@ -836,6 +838,30 @@ export const vaultReportRpc = defineRpc({
|
|
|
836
838
|
output: z.object({ on: z.boolean(), report: PromptReportSchema }),
|
|
837
839
|
});
|
|
838
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
|
+
|
|
851
|
+
/** What the office noticed and nobody dismissed, newest first. */
|
|
852
|
+
export const alertsRpc = defineRpc({
|
|
853
|
+
name: "office.alerts.request",
|
|
854
|
+
input: z.object({}),
|
|
855
|
+
output: z.object({ alerts: z.array(AlertSchema) }),
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
/** Dismisses an alert; the same thing is not raised again while it lasts. */
|
|
859
|
+
export const alertDismissRpc = defineRpc({
|
|
860
|
+
name: "office.alerts.dismiss.request",
|
|
861
|
+
input: z.object({ id: z.string() }),
|
|
862
|
+
output: z.object({ alerts: z.array(AlertSchema) }),
|
|
863
|
+
});
|
|
864
|
+
|
|
839
865
|
export const WriterModesSchema = z.object({
|
|
840
866
|
/** The provider the writer would start on now, by its label. */
|
|
841
867
|
provider: z.string(),
|
|
@@ -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
|
+
}
|
package/shared/settings.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { LANGUAGE_CHOICES } from "./scene-language.js";
|
|
|
3
3
|
import { defineSettings } from "@getpaseo/plugin";
|
|
4
4
|
import { WEATHER_MODES, MANUAL_CHOICES } from "./weather.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { PINNED_NOTES_MAX } from "./alerts.js";
|
|
6
7
|
|
|
7
8
|
/** A Jira project key and a Sentry slug: only these reach a JQL query or a Sentry address. */
|
|
8
9
|
export const JIRA_KEY = /^[A-Z][A-Z0-9_]+$/;
|
|
@@ -63,6 +64,10 @@ export function stickyNotesOf(text: string): string[] {
|
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
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
|
+
|
|
66
71
|
const HostValuesSchema = z.object({
|
|
67
72
|
...brandFields,
|
|
68
73
|
archiveOnDeparture: z.boolean().default(false),
|
|
@@ -78,6 +83,8 @@ const HostValuesSchema = z.object({
|
|
|
78
83
|
floorPlan: z.enum(FLOOR_PLANS).default("pro").catch("pro"),
|
|
79
84
|
streamerMode: z.boolean().default(true),
|
|
80
85
|
historyVault: z.boolean().default(false),
|
|
86
|
+
pinnedNotes: z.string().max(PINNED_NOTES_MAX).default(""),
|
|
87
|
+
cacheClock: z.enum(CACHE_CLOCKS).default("1h").catch("1h"),
|
|
81
88
|
stickyNotes: z.string().max(STICKY_NOTES_TEXT_MAX).default(""),
|
|
82
89
|
jiraProjects: z.string().default(""),
|
|
83
90
|
sentryOrg: z.string().default(""),
|
|
@@ -146,7 +153,9 @@ const SUNDAY_TO_THURSDAY = [0, 1, 2, 3, 4];
|
|
|
146
153
|
* sends to the floor; off, a person's bubble names what they are at. `stickyNotes` are the
|
|
147
154
|
* owner's notes on the 3D whiteboard, with `;` between them. `historyVault` on has the office
|
|
148
155
|
* keep what is said in each conversation in a file on the host; it is off until the owner turns
|
|
149
|
-
* it on. `
|
|
156
|
+
* it on. `pinnedNotes` is said again to an agent whose conversation is compacted during a turn;
|
|
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`
|
|
150
159
|
* and `sentryProjects` are the comma separated projects checked for incidents, `sentryOrg` their
|
|
151
160
|
* Sentry organisation and `sentryUrl` the Sentry the token is sent to.
|
|
152
161
|
*/
|
package/shared/timeline.ts
CHANGED
|
@@ -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
|
}
|