paseo-office 0.2.6 → 0.2.7
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 +26 -0
- package/client/office-surface.tsx +14 -0
- package/client/use-alerts.ts +71 -0
- package/docs/office.md +30 -0
- package/index.server.ts +31 -1
- package/package.json +1 -1
- package/server/live-ports.ts +7 -0
- package/server/watchers.ts +308 -0
- package/shared/alerts.ts +48 -0
- package/shared/contracts.ts +15 -0
- package/shared/settings.ts +4 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import { Icon, TextInput } from "@getpaseo/plugin/client/ui";
|
|
4
|
+
import {
|
|
5
|
+
HINT_MAX,
|
|
6
|
+
checksNote,
|
|
7
|
+
clashNote,
|
|
8
|
+
portNote,
|
|
9
|
+
type Alert,
|
|
10
|
+
type AlertKind,
|
|
11
|
+
} from "../shared/alerts.js";
|
|
12
|
+
import type { Machine } from "../shared/contracts.js";
|
|
13
|
+
import { ActionButton } from "./action-button.js";
|
|
14
|
+
import { OfficeModal as Modal } from "./office-modal.js";
|
|
15
|
+
import type { OfficeStyles } from "./styles.js";
|
|
16
|
+
import type { AgentActions } from "./use-agent-actions.js";
|
|
17
|
+
|
|
18
|
+
const layout = StyleSheet.create({
|
|
19
|
+
row: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: 8 },
|
|
20
|
+
field: { flex: 1, minWidth: 160 },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const STEER = { activeTurnBehavior: "steer" } as const;
|
|
24
|
+
|
|
25
|
+
const ABOUT: Readonly<Record<AlertKind, string>> = {
|
|
26
|
+
loop: "Stop ends its turn. A hint is sent into the turn, so the agent reads it without starting over.",
|
|
27
|
+
refused:
|
|
28
|
+
"The provider's auto mode refused this call. The agent was told and goes on; nothing is waiting for you.",
|
|
29
|
+
clash: "Tell both sends each a line about the other, into its turn.",
|
|
30
|
+
port: "Tell the agent sends it a line to use another port, into its turn.",
|
|
31
|
+
checks: "Fix it sends the failing checks to an agent of this workspace that is resting.",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface AlertCardProps {
|
|
35
|
+
/** The alert to show; null closes the card. */
|
|
36
|
+
alert: Alert | null;
|
|
37
|
+
/** The office's name for an agent, for a line sent to another one. */
|
|
38
|
+
nameOf(agentId: string): string;
|
|
39
|
+
/** The host's readings: who holds a port. */
|
|
40
|
+
machine: Machine | null;
|
|
41
|
+
actions: AgentActions;
|
|
42
|
+
styles: OfficeStyles;
|
|
43
|
+
onClose(): void;
|
|
44
|
+
onDismiss(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface ActProps extends Omit<AlertCardProps, "alert" | "onClose"> {
|
|
48
|
+
alert: Alert;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The loop's: stop the turn, or send a hint into it. */
|
|
52
|
+
function LoopActions({ alert, actions, styles, onDismiss }: ActProps) {
|
|
53
|
+
const [hint, setHint] = useState("");
|
|
54
|
+
const agentId = alert.agentId ?? "";
|
|
55
|
+
const { cancel } = actions;
|
|
56
|
+
const stop = useCallback(async () => {
|
|
57
|
+
await cancel?.(agentId);
|
|
58
|
+
await onDismiss();
|
|
59
|
+
}, [cancel, agentId, onDismiss]);
|
|
60
|
+
const send = useCallback(async () => {
|
|
61
|
+
await actions.send(agentId, hint.trim().slice(0, HINT_MAX), STEER);
|
|
62
|
+
await onDismiss();
|
|
63
|
+
}, [actions, agentId, hint, onDismiss]);
|
|
64
|
+
const field = useMemo(() => [styles.fieldInput, layout.field], [styles]);
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
<View style={layout.row}>
|
|
68
|
+
<TextInput
|
|
69
|
+
accessibilityLabel="Hint for the agent"
|
|
70
|
+
value={hint}
|
|
71
|
+
onChangeText={setHint}
|
|
72
|
+
placeholder="What it should try instead"
|
|
73
|
+
maxLength={HINT_MAX}
|
|
74
|
+
style={field}
|
|
75
|
+
/>
|
|
76
|
+
<ActionButton
|
|
77
|
+
label="Send a hint"
|
|
78
|
+
pendingLabel="Sending..."
|
|
79
|
+
onPress={send}
|
|
80
|
+
disabled={hint.trim() === ""}
|
|
81
|
+
styles={styles}
|
|
82
|
+
primary
|
|
83
|
+
/>
|
|
84
|
+
</View>
|
|
85
|
+
{cancel ? (
|
|
86
|
+
<ActionButton label="Stop" pendingLabel="Stopping..." onPress={stop} styles={styles} />
|
|
87
|
+
) : null}
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** What is sent to whom for an alert that is answered with one line; null when there is nobody to send to. */
|
|
93
|
+
function linesOf({
|
|
94
|
+
alert,
|
|
95
|
+
nameOf,
|
|
96
|
+
machine,
|
|
97
|
+
}: ActProps): { label: string; to: [string, string][] } | null {
|
|
98
|
+
const { agentId, otherAgentId } = alert;
|
|
99
|
+
if (agentId === undefined) return null;
|
|
100
|
+
if (alert.kind === "clash" && otherAgentId !== undefined) {
|
|
101
|
+
// (the alert's title names the file only when the host may name files)
|
|
102
|
+
const file = /are in (.+)$/.exec(alert.title)?.[1] ?? "the same file";
|
|
103
|
+
return {
|
|
104
|
+
label: "Tell both",
|
|
105
|
+
to: [
|
|
106
|
+
[agentId, clashNote(file, nameOf(otherAgentId))],
|
|
107
|
+
[otherAgentId, clashNote(file, nameOf(agentId))],
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (alert.kind === "port" && alert.port !== undefined) {
|
|
112
|
+
const { port } = alert;
|
|
113
|
+
const holder = machine?.agents.find(
|
|
114
|
+
(held) => held.agentId !== agentId && held.ports.includes(port),
|
|
115
|
+
);
|
|
116
|
+
const name = holder === undefined ? null : nameOf(holder.agentId);
|
|
117
|
+
return { label: "Tell the agent", to: [[agentId, portNote(port, name)]] };
|
|
118
|
+
}
|
|
119
|
+
if (alert.kind === "checks") {
|
|
120
|
+
return { label: "Fix it", to: [[agentId, checksNote(alert.detail)]] };
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function LineAction(props: ActProps) {
|
|
126
|
+
const { alert, actions, styles, onDismiss } = props;
|
|
127
|
+
const lines = linesOf(props);
|
|
128
|
+
const send = useCallback(async () => {
|
|
129
|
+
if (lines === null) return;
|
|
130
|
+
// Failing checks go to a resting agent as its prompt; the rest join a running turn.
|
|
131
|
+
const options = alert.kind === "checks" ? undefined : STEER;
|
|
132
|
+
await Promise.all(lines.to.map(([agentId, text]) => actions.send(agentId, text, options)));
|
|
133
|
+
await onDismiss();
|
|
134
|
+
}, [lines, alert.kind, actions, onDismiss]);
|
|
135
|
+
if (alert.kind === "refused") return null;
|
|
136
|
+
if (lines === null) {
|
|
137
|
+
return <Text style={styles.host.note}>No agent of this workspace is resting now.</Text>;
|
|
138
|
+
}
|
|
139
|
+
return (
|
|
140
|
+
<ActionButton
|
|
141
|
+
label={lines.label}
|
|
142
|
+
pendingLabel="Sending..."
|
|
143
|
+
onPress={send}
|
|
144
|
+
styles={styles}
|
|
145
|
+
primary
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** One thing the office noticed, with what can be done about it. */
|
|
151
|
+
export function AlertCard({ alert, onClose, ...rest }: AlertCardProps) {
|
|
152
|
+
const { styles, onDismiss } = rest;
|
|
153
|
+
const change = useCallback(
|
|
154
|
+
(next: boolean) => {
|
|
155
|
+
if (!next) onClose();
|
|
156
|
+
},
|
|
157
|
+
[onClose],
|
|
158
|
+
);
|
|
159
|
+
const icon = useMemo(
|
|
160
|
+
() => <Icon name="TriangleAlert" size={18} color={String(styles.host.label.color)} />,
|
|
161
|
+
[styles],
|
|
162
|
+
);
|
|
163
|
+
return (
|
|
164
|
+
<Modal icon={icon} title="Noticed" open={alert !== null} onOpenChange={change}>
|
|
165
|
+
<Modal.Content>
|
|
166
|
+
{alert !== null && (
|
|
167
|
+
<View style={styles.host.body}>
|
|
168
|
+
<View style={styles.host.group}>
|
|
169
|
+
<Text accessibilityRole="header" style={styles.host.title}>
|
|
170
|
+
{alert.title}
|
|
171
|
+
</Text>
|
|
172
|
+
{alert.detail !== "" && (
|
|
173
|
+
<Text selectable style={styles.rowMeta}>
|
|
174
|
+
{alert.detail}
|
|
175
|
+
</Text>
|
|
176
|
+
)}
|
|
177
|
+
<Text style={styles.host.note}>{ABOUT[alert.kind]}</Text>
|
|
178
|
+
</View>
|
|
179
|
+
{alert.kind === "loop" ? (
|
|
180
|
+
<LoopActions alert={alert} {...rest} />
|
|
181
|
+
) : (
|
|
182
|
+
<LineAction alert={alert} {...rest} />
|
|
183
|
+
)}
|
|
184
|
+
<ActionButton
|
|
185
|
+
label="Dismiss"
|
|
186
|
+
pendingLabel="Dismissing..."
|
|
187
|
+
onPress={onDismiss}
|
|
188
|
+
styles={styles}
|
|
189
|
+
/>
|
|
190
|
+
</View>
|
|
191
|
+
)}
|
|
192
|
+
</Modal.Content>
|
|
193
|
+
</Modal>
|
|
194
|
+
);
|
|
195
|
+
}
|
package/client/host-switches.tsx
CHANGED
|
@@ -34,6 +34,7 @@ type HostSetting =
|
|
|
34
34
|
| "Agent tools"
|
|
35
35
|
| "Streamer mode"
|
|
36
36
|
| "History vault"
|
|
37
|
+
| "Pinned notes"
|
|
37
38
|
| "Sticky notes"
|
|
38
39
|
| "Notes folder"
|
|
39
40
|
| "Time zone"
|
|
@@ -257,6 +258,7 @@ export function HostSwitches({
|
|
|
257
258
|
saveProblem={saveProblem}
|
|
258
259
|
styles={styles}
|
|
259
260
|
/>
|
|
261
|
+
<PinnedNotes values={stored} change={change} saveProblem={saveProblem} styles={styles} />
|
|
260
262
|
<Text style={styles.sheetLabel}>Stand-up schedule</Text>
|
|
261
263
|
<View style={styles.headerFields}>
|
|
262
264
|
<SettingField
|
|
@@ -502,6 +504,30 @@ function FloorSettings({
|
|
|
502
504
|
);
|
|
503
505
|
}
|
|
504
506
|
|
|
507
|
+
function PinnedNotes({
|
|
508
|
+
values: stored,
|
|
509
|
+
change,
|
|
510
|
+
saveProblem,
|
|
511
|
+
styles,
|
|
512
|
+
}: Omit<TrackerFieldsProps, "incidents">) {
|
|
513
|
+
const save = useCallback(
|
|
514
|
+
(next: string) => change("Pinned notes", { pinnedNotes: next }),
|
|
515
|
+
[change],
|
|
516
|
+
);
|
|
517
|
+
return (
|
|
518
|
+
<View style={styles.headerFields}>
|
|
519
|
+
<SettingField
|
|
520
|
+
label="Pinned notes"
|
|
521
|
+
hint="Said again to an agent whose conversation is compacted during a turn, so a rule you gave it is not lost. Empty says nothing."
|
|
522
|
+
value={stored?.pinnedNotes ?? null}
|
|
523
|
+
onSave={save}
|
|
524
|
+
problem={saveProblem("Pinned notes")}
|
|
525
|
+
styles={styles}
|
|
526
|
+
/>
|
|
527
|
+
</View>
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
505
531
|
function ArchiveSetting({
|
|
506
532
|
values: stored,
|
|
507
533
|
change,
|
|
@@ -63,6 +63,8 @@ import { JanitorCard } from "./janitor-card.js";
|
|
|
63
63
|
import { TimelineCard } from "./timeline-card.js";
|
|
64
64
|
import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
|
|
65
65
|
import { VaultCard } from "./vault-card.js";
|
|
66
|
+
import { AlertCard } from "./alert-card.js";
|
|
67
|
+
import { useAlerts } from "./use-alerts.js";
|
|
66
68
|
import { useSshServers } from "./ssh-hosts.js";
|
|
67
69
|
import { MachineCard } from "./machine-card.js";
|
|
68
70
|
import { hostNote, memoryPercent, namedMachine, type HostNote } from "../shared/machine-text.js";
|
|
@@ -1946,6 +1948,7 @@ export function OfficeSurface(
|
|
|
1946
1948
|
const planUsage = usePlanUsage(live);
|
|
1947
1949
|
const timeline = useTimelineCard(live);
|
|
1948
1950
|
const history = useTimelineCard(live);
|
|
1951
|
+
const alerts = useAlerts(live);
|
|
1949
1952
|
const board = useBoardSheet(model, live);
|
|
1950
1953
|
const dutyCard = useCardOpening(live);
|
|
1951
1954
|
// Until the host sends its duty list (an older host has none) nothing offers the duty board.
|
|
@@ -2075,6 +2078,7 @@ export function OfficeSurface(
|
|
|
2075
2078
|
() =>
|
|
2076
2079
|
[
|
|
2077
2080
|
incidentsStripEntry,
|
|
2081
|
+
...alerts.cards,
|
|
2078
2082
|
settingsStripEntry,
|
|
2079
2083
|
weatherStripEntry,
|
|
2080
2084
|
hostEntry,
|
|
@@ -2086,6 +2090,7 @@ export function OfficeSurface(
|
|
|
2086
2090
|
].filter((card) => card !== null),
|
|
2087
2091
|
[
|
|
2088
2092
|
incidentsStripEntry,
|
|
2093
|
+
alerts.cards,
|
|
2089
2094
|
settingsStripEntry,
|
|
2090
2095
|
weatherStripEntry,
|
|
2091
2096
|
hostEntry,
|
|
@@ -2297,6 +2302,15 @@ export function OfficeSurface(
|
|
|
2297
2302
|
/>
|
|
2298
2303
|
<TimelineCard open={timeline.open} styles={styles} onClose={timeline.close} />
|
|
2299
2304
|
<VaultCard open={history.open} styles={styles} onClose={history.close} />
|
|
2305
|
+
<AlertCard
|
|
2306
|
+
alert={alerts.open}
|
|
2307
|
+
nameOf={name}
|
|
2308
|
+
machine={machine}
|
|
2309
|
+
actions={actions}
|
|
2310
|
+
styles={styles}
|
|
2311
|
+
onClose={alerts.close}
|
|
2312
|
+
onDismiss={alerts.dismiss}
|
|
2313
|
+
/>
|
|
2300
2314
|
<JanitorCard
|
|
2301
2315
|
rows={contexts}
|
|
2302
2316
|
open={janitorOpen && live}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
3
|
+
import type { Alert } from "../shared/alerts.js";
|
|
4
|
+
import { alertDismissRpc, alertsRpc } from "../shared/contracts.js";
|
|
5
|
+
import type { StripCard } from "./attention-strip.js";
|
|
6
|
+
|
|
7
|
+
const NO_ALERTS: readonly Alert[] = [];
|
|
8
|
+
/** The office's own reads are 5 s apart: asking every other one is soon enough. */
|
|
9
|
+
const EVERY_MS = 10_000;
|
|
10
|
+
|
|
11
|
+
export interface AlertsState {
|
|
12
|
+
/** A card of the Attention strip for each alert, newest first. */
|
|
13
|
+
cards: StripCard[];
|
|
14
|
+
/** The alert whose card is open; null when none is, and once it is gone. */
|
|
15
|
+
open: Alert | null;
|
|
16
|
+
close(): void;
|
|
17
|
+
/** Dismisses the open alert and closes its card. */
|
|
18
|
+
dismiss(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What the office noticed, asked for while `live`, as cards that open one alert at a time. */
|
|
22
|
+
export function useAlerts(live: boolean): AlertsState {
|
|
23
|
+
const ask = useRpc(alertsRpc);
|
|
24
|
+
const drop = useRpc(alertDismissRpc);
|
|
25
|
+
// Kept in a ref: the poll restarts when the office goes live, not when the call's identity changes.
|
|
26
|
+
const asking = useRef(ask);
|
|
27
|
+
asking.current = ask;
|
|
28
|
+
const [alerts, setAlerts] = useState<readonly Alert[]>(NO_ALERTS);
|
|
29
|
+
const [openId, setOpenId] = useState<string | null>(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!live) {
|
|
32
|
+
setAlerts(NO_ALERTS);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
let ended = false;
|
|
36
|
+
const read = async () => {
|
|
37
|
+
try {
|
|
38
|
+
const answer = await asking.current({});
|
|
39
|
+
if (!ended) setAlerts(answer.alerts);
|
|
40
|
+
} catch {
|
|
41
|
+
// (the host went away: the next reading says)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
void read();
|
|
45
|
+
const timer = setInterval(() => void read(), EVERY_MS);
|
|
46
|
+
return () => {
|
|
47
|
+
ended = true;
|
|
48
|
+
clearInterval(timer);
|
|
49
|
+
};
|
|
50
|
+
}, [live]);
|
|
51
|
+
const cards = useMemo(
|
|
52
|
+
() =>
|
|
53
|
+
alerts.map(
|
|
54
|
+
(alert): StripCard => ({
|
|
55
|
+
title: alert.title,
|
|
56
|
+
note: { text: alert.detail || "Open to act on it", tone: "warning" },
|
|
57
|
+
onOpen: () => setOpenId(alert.id),
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
[alerts],
|
|
61
|
+
);
|
|
62
|
+
const open = useMemo(() => alerts.find((alert) => alert.id === openId) ?? null, [alerts, openId]);
|
|
63
|
+
const close = useCallback(() => setOpenId(null), []);
|
|
64
|
+
const dismiss = useCallback(async () => {
|
|
65
|
+
if (openId === null) return;
|
|
66
|
+
const answer = await drop({ id: openId });
|
|
67
|
+
setAlerts(answer.alerts);
|
|
68
|
+
setOpenId(null);
|
|
69
|
+
}, [drop, openId]);
|
|
70
|
+
return { cards, open, close, dismiss };
|
|
71
|
+
}
|
package/docs/office.md
CHANGED
|
@@ -516,6 +516,36 @@ surface is open on some device, at the directory's changes and the 5-second acti
|
|
|
516
516
|
the office was closed is a gap in every lane, not a rest, and the week's figures count only what
|
|
517
517
|
was seen. `office.timeline.request` reads it.
|
|
518
518
|
|
|
519
|
+
## What the office notices
|
|
520
|
+
|
|
521
|
+
Upstream does these with Claude Code hooks. Here the office's server does them from what it reads
|
|
522
|
+
anyway: each running agent's newest timeline entries every 5 seconds, and the directory
|
|
523
|
+
(`server/watchers.ts`). So they work for every provider, only while an office surface is open, and
|
|
524
|
+
a few seconds after the fact, not before it. Each is a card in the Attention strip; opening it
|
|
525
|
+
shows what can be done.
|
|
526
|
+
|
|
527
|
+
- **A loop.** The same call (the tool and what it was given) failed three times running. **Stop**
|
|
528
|
+
ends the turn; **Send a hint** sends a line into it. It goes when the agent gets past it or its
|
|
529
|
+
turn ends.
|
|
530
|
+
- **A refused call.** The provider's auto mode refused a call. The card has the call and the
|
|
531
|
+
reason, for half an hour. Nothing waits on it.
|
|
532
|
+
- **Two agents in one file.** Both changed the same path within ten minutes. **Tell both** sends
|
|
533
|
+
each a line about the other.
|
|
534
|
+
- **A taken port.** A command failed with "address already in use". **Tell the agent** sends it a
|
|
535
|
+
line to use another port, naming the session whose server holds it when the Host readings say.
|
|
536
|
+
- **Failing checks.** The checks of a workspace's pull request fail. **Fix it** sends the failing
|
|
537
|
+
checks to an agent of that workspace that is resting; while none rests, the card says so.
|
|
538
|
+
|
|
539
|
+
A line sent from a card joins the agent's running turn ("steer"), except Fix it, which is a
|
|
540
|
+
prompt. With streamer mode on, a card names the tool and not the file or the command.
|
|
541
|
+
|
|
542
|
+
**Pinned notes** (Settings) are said again to an agent whose conversation is compacted during a
|
|
543
|
+
turn, as a line into that turn. A compaction of a resting agent sends nothing, since that would
|
|
544
|
+
start a turn.
|
|
545
|
+
|
|
546
|
+
Not done here: blocking a call before it runs and undoing a turn's edits. Both need real Claude
|
|
547
|
+
Code hooks written into the host's `~/.claude/settings.json`.
|
|
548
|
+
|
|
519
549
|
## History vault and the prompt report
|
|
520
550
|
|
|
521
551
|
**History vault** (Settings, host-wide, off by default) has the office keep what is said in each
|
package/index.server.ts
CHANGED
|
@@ -46,6 +46,8 @@ import { probeSentry } from "./server/incidents-sentry.js";
|
|
|
46
46
|
import { createIncidentsStore, type IncidentsStore } from "./server/incidents-store.js";
|
|
47
47
|
import { projectPlanUsage } from "./server/plan-usage.js";
|
|
48
48
|
import { promptReport } from "./shared/vault.js";
|
|
49
|
+
import { pinnedNote } from "./shared/alerts.js";
|
|
50
|
+
import { createWatchers } from "./server/watchers.js";
|
|
49
51
|
import {
|
|
50
52
|
VAULT_TAIL_LIMIT,
|
|
51
53
|
VaultFileSchema,
|
|
@@ -128,6 +130,8 @@ import {
|
|
|
128
130
|
notesModesRpc,
|
|
129
131
|
planUsageRpc,
|
|
130
132
|
timelineRpc,
|
|
133
|
+
alertDismissRpc,
|
|
134
|
+
alertsRpc,
|
|
131
135
|
vaultReportRpc,
|
|
132
136
|
vaultSearchRpc,
|
|
133
137
|
vaultTalkRpc,
|
|
@@ -235,7 +239,24 @@ export function createOfficePlugin(
|
|
|
235
239
|
const holder = createPaseoHolder();
|
|
236
240
|
// Off until the settings are read: nothing is named before the host has said it may be.
|
|
237
241
|
let stepsNamed = false;
|
|
238
|
-
|
|
242
|
+
// The owner's pinned notes; empty until the settings are read.
|
|
243
|
+
let pinnedNotes = "";
|
|
244
|
+
const watchers = createWatchers({
|
|
245
|
+
now: () => deps.clock.now(),
|
|
246
|
+
named: () => stepsNamed,
|
|
247
|
+
pinnedNotes: () => pinnedNotes,
|
|
248
|
+
remind: (agentId, notes) => {
|
|
249
|
+
if (!holder.held()) return;
|
|
250
|
+
holder
|
|
251
|
+
.require()
|
|
252
|
+
.agents.ref(agentId)
|
|
253
|
+
.send(pinnedNote(notes), { activeTurnBehavior: "steer" })
|
|
254
|
+
.catch((error: unknown) =>
|
|
255
|
+
log(`[office] pinned notes to ${agentId}: ${errorMessage(error)}`),
|
|
256
|
+
);
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
const hubPorts = liveHubPorts(holder, deps.clock, log, () => stepsNamed, watchers.tail);
|
|
239
260
|
// Set once its file is read; what the office sees before that is not kept.
|
|
240
261
|
let timeline: TimelineLog | null = null;
|
|
241
262
|
const hub = createHub({
|
|
@@ -279,6 +300,7 @@ export function createOfficePlugin(
|
|
|
279
300
|
);
|
|
280
301
|
stopVault = hub.watch(vault.view);
|
|
281
302
|
})().catch((error: unknown) => log(`[office] history vault unavailable: ${errorMessage(error)}`));
|
|
303
|
+
const stopWatchers = hub.watch(watchers.view);
|
|
282
304
|
let stopTimeline: (() => void) | undefined;
|
|
283
305
|
const timelineReady = (async () => {
|
|
284
306
|
const kept = (await deps.timelineFile?.load()) ?? null;
|
|
@@ -513,6 +535,7 @@ export function createOfficePlugin(
|
|
|
513
535
|
agentToolsOn = false;
|
|
514
536
|
stepsNamed = false;
|
|
515
537
|
vaultOn = false;
|
|
538
|
+
pinnedNotes = "";
|
|
516
539
|
office.setPickupEnabled(false);
|
|
517
540
|
const message = `The office's settings cannot be read: ${reason}`;
|
|
518
541
|
log(`[office] ${message}`);
|
|
@@ -534,6 +557,7 @@ export function createOfficePlugin(
|
|
|
534
557
|
agentToolsOn = state.values.agentTools;
|
|
535
558
|
stepsNamed = !state.values.streamerMode;
|
|
536
559
|
vaultOn = state.values.historyVault;
|
|
560
|
+
pinnedNotes = state.values.pinnedNotes;
|
|
537
561
|
office.setPickupEnabled(agentToolsOn && holder.held());
|
|
538
562
|
weather.settingsChanged(state.values);
|
|
539
563
|
await notesSchedule.sync(state.values);
|
|
@@ -743,6 +767,11 @@ export function createOfficePlugin(
|
|
|
743
767
|
const start = Math.max(from, end - TIMELINE_KEEP_MS);
|
|
744
768
|
return { ok: true as const, timeline: timeline.read(start, end) };
|
|
745
769
|
});
|
|
770
|
+
server.handle(alertsRpc, async () => ({ alerts: watchers.alerts() }));
|
|
771
|
+
server.handle(alertDismissRpc, async ({ id }) => {
|
|
772
|
+
watchers.dismiss(id);
|
|
773
|
+
return { alerts: watchers.alerts() };
|
|
774
|
+
});
|
|
746
775
|
server.handle(vaultSearchRpc, async ({ query }) => {
|
|
747
776
|
await vaultReady;
|
|
748
777
|
return { on: vaultOn, hits: vaultOn ? (vault?.search(query) ?? []) : [] };
|
|
@@ -974,6 +1003,7 @@ export function createOfficePlugin(
|
|
|
974
1003
|
await lifeReady;
|
|
975
1004
|
stopLife?.();
|
|
976
1005
|
stopTimeline?.();
|
|
1006
|
+
stopWatchers();
|
|
977
1007
|
stopVault?.();
|
|
978
1008
|
await vaultSaves?.flush();
|
|
979
1009
|
await timelineSaves?.flush();
|
package/package.json
CHANGED
package/server/live-ports.ts
CHANGED
|
@@ -21,6 +21,7 @@ import type { SkillFolder } from "./paths.js";
|
|
|
21
21
|
import type { ScriptLogPorts } from "./script-log.js";
|
|
22
22
|
import { nodeSkillFiles, type SkillsPorts } from "./skills.js";
|
|
23
23
|
import type { Timers } from "./timers.js";
|
|
24
|
+
import type { WatchedEntry } from "./watchers.js";
|
|
24
25
|
|
|
25
26
|
/** Hub ports on the daemon's own API. The holder is set before the first attach. */
|
|
26
27
|
export function liveHubPorts(
|
|
@@ -29,6 +30,8 @@ export function liveHubPorts(
|
|
|
29
30
|
log: (message: string) => void,
|
|
30
31
|
/** Whether steps name what they are at: the host's streamer mode is off. */
|
|
31
32
|
named: () => boolean = () => false,
|
|
33
|
+
/** Told each read's entries, for whoever watches the calls themselves. */
|
|
34
|
+
onTail?: (agentId: string, entries: readonly WatchedEntry[]) => void,
|
|
32
35
|
): HubPorts {
|
|
33
36
|
return {
|
|
34
37
|
openDirectory: (onChange, onEnd) => openPaseoDirectory(holder.require(), onChange, log, onEnd),
|
|
@@ -40,6 +43,10 @@ export function liveHubPorts(
|
|
|
40
43
|
const page = await paseo.agents
|
|
41
44
|
.ref(agentId)
|
|
42
45
|
.timeline.refetch({ direction: "tail", limit: ACTIVITY_TAIL_LIMIT });
|
|
46
|
+
onTail?.(
|
|
47
|
+
agentId,
|
|
48
|
+
page.entries.map((entry) => ({ seq: entry.seqEnd, item: entry.item })),
|
|
49
|
+
);
|
|
43
50
|
return page.entries.map((entry) => entry.item);
|
|
44
51
|
},
|
|
45
52
|
timers,
|
|
@@ -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,7 @@ 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";
|
|
7
8
|
import { PromptReportSchema, VaultHitSchema, VaultTalkSchema } from "./vault.js";
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
// In their own file, so code that needs only a name does not load the schemas.
|
|
@@ -836,6 +837,20 @@ export const vaultReportRpc = defineRpc({
|
|
|
836
837
|
output: z.object({ on: z.boolean(), report: PromptReportSchema }),
|
|
837
838
|
});
|
|
838
839
|
|
|
840
|
+
/** What the office noticed and nobody dismissed, newest first. */
|
|
841
|
+
export const alertsRpc = defineRpc({
|
|
842
|
+
name: "office.alerts.request",
|
|
843
|
+
input: z.object({}),
|
|
844
|
+
output: z.object({ alerts: z.array(AlertSchema) }),
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
/** Dismisses an alert; the same thing is not raised again while it lasts. */
|
|
848
|
+
export const alertDismissRpc = defineRpc({
|
|
849
|
+
name: "office.alerts.dismiss.request",
|
|
850
|
+
input: z.object({ id: z.string() }),
|
|
851
|
+
output: z.object({ alerts: z.array(AlertSchema) }),
|
|
852
|
+
});
|
|
853
|
+
|
|
839
854
|
export const WriterModesSchema = z.object({
|
|
840
855
|
/** The provider the writer would start on now, by its label. */
|
|
841
856
|
provider: z.string(),
|
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_]+$/;
|
|
@@ -78,6 +79,7 @@ const HostValuesSchema = z.object({
|
|
|
78
79
|
floorPlan: z.enum(FLOOR_PLANS).default("pro").catch("pro"),
|
|
79
80
|
streamerMode: z.boolean().default(true),
|
|
80
81
|
historyVault: z.boolean().default(false),
|
|
82
|
+
pinnedNotes: z.string().max(PINNED_NOTES_MAX).default(""),
|
|
81
83
|
stickyNotes: z.string().max(STICKY_NOTES_TEXT_MAX).default(""),
|
|
82
84
|
jiraProjects: z.string().default(""),
|
|
83
85
|
sentryOrg: z.string().default(""),
|
|
@@ -146,7 +148,8 @@ const SUNDAY_TO_THURSDAY = [0, 1, 2, 3, 4];
|
|
|
146
148
|
* sends to the floor; off, a person's bubble names what they are at. `stickyNotes` are the
|
|
147
149
|
* owner's notes on the 3D whiteboard, with `;` between them. `historyVault` on has the office
|
|
148
150
|
* keep what is said in each conversation in a file on the host; it is off until the owner turns
|
|
149
|
-
* it on. `
|
|
151
|
+
* it on. `pinnedNotes` is said again to an agent whose conversation is compacted during a turn;
|
|
152
|
+
* empty says nothing. `jiraProjects`
|
|
150
153
|
* and `sentryProjects` are the comma separated projects checked for incidents, `sentryOrg` their
|
|
151
154
|
* Sentry organisation and `sentryUrl` the Sentry the token is sent to.
|
|
152
155
|
*/
|