paseo-office 0.2.4 → 0.2.6
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/activity-panel.tsx +21 -1
- package/client/host-switches.tsx +24 -0
- package/client/office-surface.tsx +108 -8
- package/client/timeline-card.tsx +446 -0
- package/client/timeline-open.ts +7 -0
- package/client/vault-card.tsx +316 -0
- package/docs/office.md +38 -0
- package/index.server.ts +105 -2
- package/package.json +1 -1
- package/server/paths.ts +10 -0
- package/server/timeline.ts +218 -0
- package/server/vault.ts +168 -0
- package/shared/contracts.ts +39 -0
- package/shared/settings.ts +4 -1
- package/shared/timeline.ts +177 -0
- package/shared/vault.ts +127 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import { Icon, TextInput } from "@getpaseo/plugin/client/ui";
|
|
4
|
+
import { useRpc } from "@getpaseo/plugin/client";
|
|
5
|
+
import { vaultReportRpc, vaultSearchRpc, vaultTalkRpc } from "../shared/contracts.js";
|
|
6
|
+
import {
|
|
7
|
+
RULE_TEXT,
|
|
8
|
+
type PromptReport,
|
|
9
|
+
type VaultHit,
|
|
10
|
+
type VaultMessage,
|
|
11
|
+
type VaultTalk,
|
|
12
|
+
} from "../shared/vault.js";
|
|
13
|
+
import { ActionButton } from "./action-button.js";
|
|
14
|
+
import { OfficeModal as Modal } from "./office-modal.js";
|
|
15
|
+
import { SegmentPill } from "./segment-pill.js";
|
|
16
|
+
import type { OfficeStyles } from "./styles.js";
|
|
17
|
+
|
|
18
|
+
type Tab = "search" | "report";
|
|
19
|
+
|
|
20
|
+
const OFF =
|
|
21
|
+
"The history vault is off. With History vault on in the office's settings, the office keeps what is said in each conversation in a file on this host, and it can be searched here.";
|
|
22
|
+
|
|
23
|
+
const layout = StyleSheet.create({
|
|
24
|
+
search: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
25
|
+
field: { flex: 1 },
|
|
26
|
+
list: { gap: 12 },
|
|
27
|
+
hit: { gap: 2 },
|
|
28
|
+
head: { flexDirection: "row", justifyContent: "space-between", gap: 8 },
|
|
29
|
+
rule: { gap: 3 },
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
function whenText(at: number): string {
|
|
33
|
+
const date = new Date(at);
|
|
34
|
+
const pad = (value: number) => String(value).padStart(2, "0");
|
|
35
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const WHO = { user: "You", assistant: "Agent" } as const;
|
|
39
|
+
|
|
40
|
+
function Hit({
|
|
41
|
+
hit,
|
|
42
|
+
onOpen,
|
|
43
|
+
styles,
|
|
44
|
+
}: {
|
|
45
|
+
hit: VaultHit;
|
|
46
|
+
onOpen(agentId: string): void;
|
|
47
|
+
styles: OfficeStyles;
|
|
48
|
+
}) {
|
|
49
|
+
const press = useCallback(() => onOpen(hit.agentId), [onOpen, hit.agentId]);
|
|
50
|
+
return (
|
|
51
|
+
<Pressable
|
|
52
|
+
accessibilityRole="button"
|
|
53
|
+
accessibilityLabel={`${hit.name}, ${whenText(hit.at)}: ${hit.snippet}`}
|
|
54
|
+
onPress={press}
|
|
55
|
+
style={layout.hit}
|
|
56
|
+
>
|
|
57
|
+
<View style={layout.head}>
|
|
58
|
+
<Text style={styles.host.name} numberOfLines={1}>
|
|
59
|
+
{hit.name}
|
|
60
|
+
</Text>
|
|
61
|
+
<Text style={styles.host.note}>
|
|
62
|
+
{hit.team} · {whenText(hit.at)}
|
|
63
|
+
</Text>
|
|
64
|
+
</View>
|
|
65
|
+
<Text style={styles.host.note}>
|
|
66
|
+
{WHO[hit.role]}: {hit.snippet}
|
|
67
|
+
</Text>
|
|
68
|
+
</Pressable>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function Message({ message, styles }: { message: VaultMessage; styles: OfficeStyles }) {
|
|
73
|
+
return (
|
|
74
|
+
<View style={layout.hit}>
|
|
75
|
+
<Text style={styles.host.note}>
|
|
76
|
+
{WHO[message.role]} · {whenText(message.at)}
|
|
77
|
+
</Text>
|
|
78
|
+
<Text selectable style={styles.rowMeta}>
|
|
79
|
+
{message.text}
|
|
80
|
+
</Text>
|
|
81
|
+
</View>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Talk({ talk, onBack, styles }: { talk: VaultTalk; onBack(): void; styles: OfficeStyles }) {
|
|
86
|
+
return (
|
|
87
|
+
<View style={styles.host.body}>
|
|
88
|
+
<View style={layout.head}>
|
|
89
|
+
<Text accessibilityRole="header" style={styles.host.title}>
|
|
90
|
+
{talk.name} · {talk.team}
|
|
91
|
+
</Text>
|
|
92
|
+
<ActionButton label="Back" pendingLabel="Back" onPress={onBack} styles={styles} />
|
|
93
|
+
</View>
|
|
94
|
+
<View style={layout.list}>
|
|
95
|
+
{talk.messages.map((message) => (
|
|
96
|
+
<Message key={`${message.at}:${message.role}`} message={message} styles={styles} />
|
|
97
|
+
))}
|
|
98
|
+
</View>
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function Report({ report, styles }: { report: PromptReport; styles: OfficeStyles }) {
|
|
104
|
+
if (report.total === 0) {
|
|
105
|
+
return <Text style={styles.host.empty}>No prompt of the last seven days is in the vault.</Text>;
|
|
106
|
+
}
|
|
107
|
+
return (
|
|
108
|
+
<View style={styles.host.body}>
|
|
109
|
+
<Text style={styles.host.title}>
|
|
110
|
+
{report.clean} of {report.total} prompts had nothing to improve
|
|
111
|
+
</Text>
|
|
112
|
+
<View style={layout.list}>
|
|
113
|
+
{report.rules.map((entry) => (
|
|
114
|
+
<View key={entry.rule} style={layout.rule}>
|
|
115
|
+
<Text style={styles.host.name}>
|
|
116
|
+
{RULE_TEXT[entry.rule].title}: {entry.count}
|
|
117
|
+
</Text>
|
|
118
|
+
<Text style={styles.host.note}>{RULE_TEXT[entry.rule].advice}</Text>
|
|
119
|
+
{entry.examples.map((example, index) => (
|
|
120
|
+
// (two prompts of the same words are two examples)
|
|
121
|
+
// oxlint-disable-next-line react/no-array-index-key
|
|
122
|
+
<Text key={`${index}:${example}`} style={styles.rowMeta}>
|
|
123
|
+
“{example}”
|
|
124
|
+
</Text>
|
|
125
|
+
))}
|
|
126
|
+
</View>
|
|
127
|
+
))}
|
|
128
|
+
</View>
|
|
129
|
+
<Text style={styles.host.note}>
|
|
130
|
+
The prompt helper's rules, applied on this host to the prompts of the last seven days
|
|
131
|
+
that are in the vault. No model reads them.
|
|
132
|
+
</Text>
|
|
133
|
+
</View>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface Found {
|
|
138
|
+
on: boolean;
|
|
139
|
+
hits: VaultHit[];
|
|
140
|
+
query: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function problemOf(error: unknown): string {
|
|
144
|
+
return error instanceof Error ? error.message : String(error);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The search: what was asked last, what it found, and the conversation that is open. */
|
|
148
|
+
function useVaultSearch() {
|
|
149
|
+
const search = useRpc(vaultSearchRpc);
|
|
150
|
+
const read = useRpc(vaultTalkRpc);
|
|
151
|
+
const [draft, setDraft] = useState("");
|
|
152
|
+
const [found, setFound] = useState<Found | null>(null);
|
|
153
|
+
const [talk, setTalk] = useState<VaultTalk | null>(null);
|
|
154
|
+
const [problem, setProblem] = useState<string | null>(null);
|
|
155
|
+
const submit = useCallback(async () => {
|
|
156
|
+
const query = draft.trim();
|
|
157
|
+
setProblem(null);
|
|
158
|
+
try {
|
|
159
|
+
const answer = await search({ query });
|
|
160
|
+
setFound({ ...answer, query });
|
|
161
|
+
} catch (error) {
|
|
162
|
+
setProblem(`The vault cannot be searched: ${problemOf(error)}`);
|
|
163
|
+
}
|
|
164
|
+
}, [draft, search]);
|
|
165
|
+
const open = useCallback(
|
|
166
|
+
(agentId: string) => {
|
|
167
|
+
setProblem(null);
|
|
168
|
+
read({ agentId }).then(
|
|
169
|
+
(answer) => {
|
|
170
|
+
if (answer.talk === null) setProblem("That conversation is no longer in the vault.");
|
|
171
|
+
else setTalk(answer.talk);
|
|
172
|
+
return undefined;
|
|
173
|
+
},
|
|
174
|
+
(error: unknown) => setProblem(`The conversation cannot be read: ${problemOf(error)}`),
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
[read],
|
|
178
|
+
);
|
|
179
|
+
const back = useCallback(() => setTalk(null), []);
|
|
180
|
+
return { draft, setDraft, found, talk, problem, submit, open, back };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function Search({ styles }: { styles: OfficeStyles }) {
|
|
184
|
+
const { draft, setDraft, found, talk, problem, submit, open, back } = useVaultSearch();
|
|
185
|
+
const submitNow = useCallback(() => void submit(), [submit]);
|
|
186
|
+
const field = useMemo(() => [styles.fieldInput, layout.field], [styles]);
|
|
187
|
+
if (talk !== null) return <Talk talk={talk} onBack={back} styles={styles} />;
|
|
188
|
+
return (
|
|
189
|
+
<View style={styles.host.body}>
|
|
190
|
+
<View style={layout.search}>
|
|
191
|
+
<TextInput
|
|
192
|
+
accessibilityLabel="Search the history"
|
|
193
|
+
value={draft}
|
|
194
|
+
onChangeText={setDraft}
|
|
195
|
+
onSubmitEditing={submitNow}
|
|
196
|
+
placeholder="Words said in a conversation"
|
|
197
|
+
autoCapitalize="none"
|
|
198
|
+
autoCorrect={false}
|
|
199
|
+
style={field}
|
|
200
|
+
/>
|
|
201
|
+
<ActionButton
|
|
202
|
+
label="Find"
|
|
203
|
+
pendingLabel="Finding..."
|
|
204
|
+
onPress={submit}
|
|
205
|
+
disabled={draft.trim() === ""}
|
|
206
|
+
styles={styles}
|
|
207
|
+
primary
|
|
208
|
+
/>
|
|
209
|
+
</View>
|
|
210
|
+
{problem && (
|
|
211
|
+
<Text accessibilityRole="alert" style={styles.actionError}>
|
|
212
|
+
{problem}
|
|
213
|
+
</Text>
|
|
214
|
+
)}
|
|
215
|
+
{found !== null && !found.on && <Text style={styles.host.empty}>{OFF}</Text>}
|
|
216
|
+
{found !== null && found.on && found.hits.length === 0 && (
|
|
217
|
+
<Text style={styles.host.empty}>Nothing in the vault has “{found.query}”.</Text>
|
|
218
|
+
)}
|
|
219
|
+
{found !== null && found.hits.length > 0 && (
|
|
220
|
+
<View style={layout.list}>
|
|
221
|
+
{found.hits.map((hit) => (
|
|
222
|
+
<Hit
|
|
223
|
+
key={`${hit.agentId}:${hit.at}:${hit.role}`}
|
|
224
|
+
hit={hit}
|
|
225
|
+
onOpen={open}
|
|
226
|
+
styles={styles}
|
|
227
|
+
/>
|
|
228
|
+
))}
|
|
229
|
+
</View>
|
|
230
|
+
)}
|
|
231
|
+
</View>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function ReportTab({ styles }: { styles: OfficeStyles }) {
|
|
236
|
+
const ask = useRpc(vaultReportRpc);
|
|
237
|
+
// Kept in a ref: the report is read once when the tab shows, whatever the call's identity.
|
|
238
|
+
const asking = useRef(ask);
|
|
239
|
+
asking.current = ask;
|
|
240
|
+
const [read, setRead] = useState<{ on: boolean; report: PromptReport } | string | null>(null);
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
let ended = false;
|
|
243
|
+
asking.current({}).then(
|
|
244
|
+
(answer) => {
|
|
245
|
+
if (!ended) setRead(answer);
|
|
246
|
+
return undefined;
|
|
247
|
+
},
|
|
248
|
+
(error: unknown) => {
|
|
249
|
+
if (!ended) setRead(`The report cannot be read: ${problemOf(error)}`);
|
|
250
|
+
},
|
|
251
|
+
);
|
|
252
|
+
return () => {
|
|
253
|
+
ended = true;
|
|
254
|
+
};
|
|
255
|
+
}, []);
|
|
256
|
+
if (read === null) return <Text style={styles.host.empty}>Reading the prompts...</Text>;
|
|
257
|
+
if (typeof read === "string") {
|
|
258
|
+
return (
|
|
259
|
+
<Text accessibilityRole="alert" style={styles.actionError}>
|
|
260
|
+
{read}
|
|
261
|
+
</Text>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (!read.on) return <Text style={styles.host.empty}>{OFF}</Text>;
|
|
265
|
+
return <Report report={read.report} styles={styles} />;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export interface VaultCardProps {
|
|
269
|
+
open: boolean;
|
|
270
|
+
styles: OfficeStyles;
|
|
271
|
+
onClose(): void;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** The history vault: a search of what was said, and the week's prompts against the prompt helper's rules. */
|
|
275
|
+
export function VaultCard({ open, styles, onClose }: VaultCardProps) {
|
|
276
|
+
const [tab, setTab] = useState<Tab>("search");
|
|
277
|
+
const change = useCallback(
|
|
278
|
+
(next: boolean) => {
|
|
279
|
+
if (!next) onClose();
|
|
280
|
+
},
|
|
281
|
+
[onClose],
|
|
282
|
+
);
|
|
283
|
+
const icon = useMemo(
|
|
284
|
+
() => <Icon name="Archive" size={18} color={String(styles.host.label.color)} />,
|
|
285
|
+
[styles],
|
|
286
|
+
);
|
|
287
|
+
return (
|
|
288
|
+
<Modal icon={icon} title="History" open={open} onOpenChange={change}>
|
|
289
|
+
<Modal.Content>
|
|
290
|
+
{open && (
|
|
291
|
+
<View style={styles.host.body}>
|
|
292
|
+
<View role="group" aria-label="History" style={styles.segments}>
|
|
293
|
+
<SegmentPill<Tab>
|
|
294
|
+
value="search"
|
|
295
|
+
name="Search"
|
|
296
|
+
on={tab === "search"}
|
|
297
|
+
disabled={false}
|
|
298
|
+
onPress={setTab}
|
|
299
|
+
styles={styles}
|
|
300
|
+
/>
|
|
301
|
+
<SegmentPill<Tab>
|
|
302
|
+
value="report"
|
|
303
|
+
name="Prompt report"
|
|
304
|
+
on={tab === "report"}
|
|
305
|
+
disabled={false}
|
|
306
|
+
onPress={setTab}
|
|
307
|
+
styles={styles}
|
|
308
|
+
/>
|
|
309
|
+
</View>
|
|
310
|
+
{tab === "search" ? <Search styles={styles} /> : <ReportTab styles={styles} />}
|
|
311
|
+
</View>
|
|
312
|
+
)}
|
|
313
|
+
</Modal.Content>
|
|
314
|
+
</Modal>
|
|
315
|
+
);
|
|
316
|
+
}
|
package/docs/office.md
CHANGED
|
@@ -497,6 +497,44 @@ The gear in fullscreen opens **Office settings** over the floor. You can also op
|
|
|
497
497
|
|
|
498
498
|
View and sound preferences apply to the device. The host stores the floor plan, branding, automation and integration settings. The [branding defaults](#custom-branding) can also come from the daemon environment.
|
|
499
499
|
|
|
500
|
+
## Timeline and the week
|
|
501
|
+
|
|
502
|
+
The **Timeline** button, in the toolbar of a wide office and at the top of the Activity tab, opens a card with a lane for each agent over the last hour,
|
|
503
|
+
6 hours or 24 hours: green at work, amber waiting for the user, red stopped on an error, grey
|
|
504
|
+
resting, and a mark at each tool call. **Replay** moves a head across the lanes from the start of
|
|
505
|
+
the range at 30, 60 or 120 times the clock, and each lane says what its agent was at then
|
|
506
|
+
("editing", "running tests", "waiting for you"). **Now** ends the replay. The replay is in the card
|
|
507
|
+
only: the 3D floor keeps showing the present.
|
|
508
|
+
|
|
509
|
+
**This week** adds the last seven days up: time at work, turns started, edits, commands, cost where
|
|
510
|
+
the provider reports one, the busiest team, and a bar for each 24 hours.
|
|
511
|
+
|
|
512
|
+
The office's server keeps this log itself (`server/timeline.ts`, `office/timeline.json`, mode 600):
|
|
513
|
+
each change of an agent's state, the kind of each tool call (never its file, command or text) and
|
|
514
|
+
each rise of its cost, for eight days and at most 40,000 marks. It sees only while an office
|
|
515
|
+
surface is open on some device, at the directory's changes and the 5-second activity reads. A time
|
|
516
|
+
the office was closed is a gap in every lane, not a rest, and the week's figures count only what
|
|
517
|
+
was seen. `office.timeline.request` reads it.
|
|
518
|
+
|
|
519
|
+
## History vault and the prompt report
|
|
520
|
+
|
|
521
|
+
**History vault** (Settings, host-wide, off by default) has the office keep what is said in each
|
|
522
|
+
conversation: the prompts and the replies, not the tool calls. It reads an agent's timeline through
|
|
523
|
+
Paseo when it first sees the agent and after each of its turns, for every provider, so it holds
|
|
524
|
+
what was said while an office surface was open. A message is cut at 2,000 characters, a
|
|
525
|
+
conversation at its newest 300 messages, and the vault at its 200 most recent conversations. It is
|
|
526
|
+
one file on the host, `office/vault.json`, mode 600; turning the setting off stops the reading and
|
|
527
|
+
hides what is kept, and deleting the file empties it.
|
|
528
|
+
|
|
529
|
+
**History**, in the toolbar of a wide office and at the top of the Activity tab, searches it with **Find**: the
|
|
530
|
+
newest 40 messages that hold every word typed, each with the words around the match. A hit opens
|
|
531
|
+
its conversation, which stays readable after the agent is archived.
|
|
532
|
+
|
|
533
|
+
**Prompt report**, the card's other tab, puts the last seven days' prompts in the vault against the
|
|
534
|
+
prompt helper's rules (`shared/upstream/prompt-coach.js`): how many had nothing to improve, and for
|
|
535
|
+
each rule how many prompts it spoke to, with up to three of them. It is worked out on the host by
|
|
536
|
+
the helper's own code. No model reads the prompts.
|
|
537
|
+
|
|
500
538
|
## Streamer mode, graphics and sticky notes
|
|
501
539
|
|
|
502
540
|
**Streamer mode** (Settings, host-wide, on by default) keeps file names, commands, search queries
|
package/index.server.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { createStreetWatch, streetReaders } from "./server/street-watch.js";
|
|
|
9
9
|
import { streetSubscription } from "./shared/contracts.js";
|
|
10
10
|
import { createLifeFeed } from "./server/life-feed.js";
|
|
11
11
|
import { createLifeFile, createSaveQueue, type LifeFile } from "./server/life-store.js";
|
|
12
|
-
import { liftFile, tenureFile } from "./server/paths.js";
|
|
12
|
+
import { liftFile, tenureFile, timelineFile, vaultFile } from "./server/paths.js";
|
|
13
13
|
import { createDepartureArchiver } from "./server/home-departure.js";
|
|
14
14
|
import {
|
|
15
15
|
lifeSubscription,
|
|
@@ -45,6 +45,21 @@ import {
|
|
|
45
45
|
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
|
+
import { promptReport } from "./shared/vault.js";
|
|
49
|
+
import {
|
|
50
|
+
VAULT_TAIL_LIMIT,
|
|
51
|
+
VaultFileSchema,
|
|
52
|
+
createVault,
|
|
53
|
+
type Vault,
|
|
54
|
+
type VaultFile,
|
|
55
|
+
} from "./server/vault.js";
|
|
56
|
+
import {
|
|
57
|
+
TIMELINE_KEEP_MS,
|
|
58
|
+
TimelineFileSchema,
|
|
59
|
+
createTimelineLog,
|
|
60
|
+
type TimelineFile,
|
|
61
|
+
type TimelineLog,
|
|
62
|
+
} from "./server/timeline.js";
|
|
48
63
|
import { TEAM_NAME_KEY, teamNameOf, tidyTeamName } from "./shared/team-name.js";
|
|
49
64
|
import {
|
|
50
65
|
changeSavedTrackers,
|
|
@@ -112,6 +127,10 @@ import {
|
|
|
112
127
|
incidentsDismissRpc,
|
|
113
128
|
notesModesRpc,
|
|
114
129
|
planUsageRpc,
|
|
130
|
+
timelineRpc,
|
|
131
|
+
vaultReportRpc,
|
|
132
|
+
vaultSearchRpc,
|
|
133
|
+
vaultTalkRpc,
|
|
115
134
|
teamRenameRpc,
|
|
116
135
|
trackersSaveRpc,
|
|
117
136
|
trackersTestRpc,
|
|
@@ -149,6 +168,10 @@ export interface OfficePluginDeps {
|
|
|
149
168
|
/** Where the team chat keeps its conversation. */
|
|
150
169
|
chatStore: ChatStore;
|
|
151
170
|
tenureFile: LifeFile<TenureLedger>;
|
|
171
|
+
/** Where the timeline is kept; without it the timeline lasts as long as the server. */
|
|
172
|
+
timelineFile?: LifeFile<TimelineFile>;
|
|
173
|
+
/** Where the history vault is kept; without it the vault lasts as long as the server. */
|
|
174
|
+
vaultFile?: LifeFile<VaultFile>;
|
|
152
175
|
liftFile: LifeFile<LiftKept>;
|
|
153
176
|
/** The owner's duty list. */
|
|
154
177
|
dutiesFile: LifeFile<DutiesFile>;
|
|
@@ -212,7 +235,59 @@ export function createOfficePlugin(
|
|
|
212
235
|
const holder = createPaseoHolder();
|
|
213
236
|
// Off until the settings are read: nothing is named before the host has said it may be.
|
|
214
237
|
let stepsNamed = false;
|
|
215
|
-
const
|
|
238
|
+
const hubPorts = liveHubPorts(holder, deps.clock, log, () => stepsNamed);
|
|
239
|
+
// Set once its file is read; what the office sees before that is not kept.
|
|
240
|
+
let timeline: TimelineLog | null = null;
|
|
241
|
+
const hub = createHub({
|
|
242
|
+
...hubPorts,
|
|
243
|
+
startActivity: (running, onChange) =>
|
|
244
|
+
hubPorts.startActivity(running, (activity, doing, ...rest) => {
|
|
245
|
+
timeline?.steps(doing);
|
|
246
|
+
onChange(activity, doing, ...rest);
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
const timelineSaves =
|
|
250
|
+
deps.timelineFile === undefined
|
|
251
|
+
? null
|
|
252
|
+
: createSaveQueue(deps.timelineFile, deps.clock, log, 30_000);
|
|
253
|
+
// Off until the settings are read: nothing is kept before the owner has said it may be.
|
|
254
|
+
let vaultOn = false;
|
|
255
|
+
let vault: Vault | null = null;
|
|
256
|
+
const vaultSaves =
|
|
257
|
+
deps.vaultFile === undefined ? null : createSaveQueue(deps.vaultFile, deps.clock, log, 30_000);
|
|
258
|
+
let stopVault: (() => void) | undefined;
|
|
259
|
+
const vaultReady = (async () => {
|
|
260
|
+
const kept = (await deps.vaultFile?.load()) ?? null;
|
|
261
|
+
vault = createVault(
|
|
262
|
+
{
|
|
263
|
+
tail: async (agentId) => {
|
|
264
|
+
const page = await holder
|
|
265
|
+
.require()
|
|
266
|
+
.agents.ref(agentId)
|
|
267
|
+
.timeline.refetch({ direction: "tail", limit: VAULT_TAIL_LIMIT });
|
|
268
|
+
return page.entries.map((entry) => ({
|
|
269
|
+
at: Date.parse(entry.timestamp),
|
|
270
|
+
seq: entry.seqEnd,
|
|
271
|
+
item: entry.item,
|
|
272
|
+
}));
|
|
273
|
+
},
|
|
274
|
+
on: () => vaultOn,
|
|
275
|
+
save: (file) => vaultSaves?.save(file),
|
|
276
|
+
log,
|
|
277
|
+
},
|
|
278
|
+
kept,
|
|
279
|
+
);
|
|
280
|
+
stopVault = hub.watch(vault.view);
|
|
281
|
+
})().catch((error: unknown) => log(`[office] history vault unavailable: ${errorMessage(error)}`));
|
|
282
|
+
let stopTimeline: (() => void) | undefined;
|
|
283
|
+
const timelineReady = (async () => {
|
|
284
|
+
const kept = (await deps.timelineFile?.load()) ?? null;
|
|
285
|
+
timeline = createTimelineLog(
|
|
286
|
+
{ now: () => deps.clock.now(), save: (file) => timelineSaves?.save(file) },
|
|
287
|
+
kept,
|
|
288
|
+
);
|
|
289
|
+
stopTimeline = hub.watch(timeline.view);
|
|
290
|
+
})().catch((error: unknown) => log(`[office] timeline unavailable: ${errorMessage(error)}`));
|
|
216
291
|
hub.setBrand(hostBrand({}, deps.env));
|
|
217
292
|
const office = createOffice({
|
|
218
293
|
store: deps.store,
|
|
@@ -437,6 +512,7 @@ export function createOfficePlugin(
|
|
|
437
512
|
function settingsUnreadable(reason: string): void {
|
|
438
513
|
agentToolsOn = false;
|
|
439
514
|
stepsNamed = false;
|
|
515
|
+
vaultOn = false;
|
|
440
516
|
office.setPickupEnabled(false);
|
|
441
517
|
const message = `The office's settings cannot be read: ${reason}`;
|
|
442
518
|
log(`[office] ${message}`);
|
|
@@ -457,6 +533,7 @@ export function createOfficePlugin(
|
|
|
457
533
|
hub.setBrand(hostBrand(state.values, deps.env));
|
|
458
534
|
agentToolsOn = state.values.agentTools;
|
|
459
535
|
stepsNamed = !state.values.streamerMode;
|
|
536
|
+
vaultOn = state.values.historyVault;
|
|
460
537
|
office.setPickupEnabled(agentToolsOn && holder.held());
|
|
461
538
|
weather.settingsChanged(state.values);
|
|
462
539
|
await notesSchedule.sync(state.values);
|
|
@@ -659,6 +736,26 @@ export function createOfficePlugin(
|
|
|
659
736
|
throw error;
|
|
660
737
|
}
|
|
661
738
|
}
|
|
739
|
+
server.handle(timelineRpc, async ({ from, to }) => {
|
|
740
|
+
await timelineReady;
|
|
741
|
+
if (timeline === null) return { ok: false as const, problem: "The timeline cannot be read" };
|
|
742
|
+
const end = Math.min(to, deps.clock.now());
|
|
743
|
+
const start = Math.max(from, end - TIMELINE_KEEP_MS);
|
|
744
|
+
return { ok: true as const, timeline: timeline.read(start, end) };
|
|
745
|
+
});
|
|
746
|
+
server.handle(vaultSearchRpc, async ({ query }) => {
|
|
747
|
+
await vaultReady;
|
|
748
|
+
return { on: vaultOn, hits: vaultOn ? (vault?.search(query) ?? []) : [] };
|
|
749
|
+
});
|
|
750
|
+
server.handle(vaultTalkRpc, async ({ agentId }) => {
|
|
751
|
+
await vaultReady;
|
|
752
|
+
return { talk: vaultOn ? (vault?.talk(agentId) ?? null) : null };
|
|
753
|
+
});
|
|
754
|
+
server.handle(vaultReportRpc, async () => {
|
|
755
|
+
await vaultReady;
|
|
756
|
+
const from = deps.clock.now() - 7 * 24 * 60 * 60 * 1000;
|
|
757
|
+
return { on: vaultOn, report: vault?.report(from) ?? promptReport([]) };
|
|
758
|
+
});
|
|
662
759
|
server.handle(planUsageRpc, async (_input, context) => {
|
|
663
760
|
holder.remember(context.paseo);
|
|
664
761
|
try {
|
|
@@ -876,6 +973,10 @@ export function createOfficePlugin(
|
|
|
876
973
|
streets.stop();
|
|
877
974
|
await lifeReady;
|
|
878
975
|
stopLife?.();
|
|
976
|
+
stopTimeline?.();
|
|
977
|
+
stopVault?.();
|
|
978
|
+
await vaultSaves?.flush();
|
|
979
|
+
await timelineSaves?.flush();
|
|
879
980
|
for (const close of listeners.values()) close();
|
|
880
981
|
await Promise.all([tenureSaves.flush(), liftSaved]);
|
|
881
982
|
machine.stop();
|
|
@@ -906,6 +1007,8 @@ export default function contribute(server: PluginServerContext): () => Promise<v
|
|
|
906
1007
|
log,
|
|
907
1008
|
}),
|
|
908
1009
|
tenureFile: createLifeFile(tenureFile(process.env, homedir()), TenureLedgerSchema),
|
|
1010
|
+
timelineFile: createLifeFile(timelineFile(process.env, homedir()), TimelineFileSchema),
|
|
1011
|
+
vaultFile: createLifeFile(vaultFile(process.env, homedir()), VaultFileSchema),
|
|
909
1012
|
liftFile: createLifeFile(liftFile(process.env, homedir()), LiftKeptSchema),
|
|
910
1013
|
dutiesFile: dutiesFileStore(dutiesFile(process.env, homedir()), { now: () => Date.now(), log }),
|
|
911
1014
|
chatStore: createChatStore({
|
package/package.json
CHANGED
package/server/paths.ts
CHANGED
|
@@ -76,6 +76,16 @@ export function liftFile(env: NodeJS.ProcessEnv, home: string) {
|
|
|
76
76
|
return join(officeDir(env, home), "lift.json");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** What the office saw each agent do, for the timeline and the week's recap. */
|
|
80
|
+
export function timelineFile(env: NodeJS.ProcessEnv, home: string) {
|
|
81
|
+
return join(officeDir(env, home), "timeline.json");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** What was said in each conversation, while the owner has the history vault on. */
|
|
85
|
+
export function vaultFile(env: NodeJS.ProcessEnv, home: string) {
|
|
86
|
+
return join(officeDir(env, home), "vault.json");
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
export function tenureFile(env: NodeJS.ProcessEnv, home: string) {
|
|
80
90
|
return join(officeDir(env, home), "tenure.json");
|
|
81
91
|
}
|