paseo-office 0.2.5 → 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 +10 -1
- package/client/host-switches.tsx +24 -0
- package/client/office-surface.tsx +65 -10
- package/client/timeline-open.ts +3 -0
- package/client/vault-card.tsx +316 -0
- package/docs/office.md +19 -0
- package/index.server.ts +61 -1
- package/package.json +1 -1
- package/server/paths.ts +5 -0
- package/server/vault.ts +168 -0
- package/shared/contracts.ts +25 -0
- package/shared/settings.ts +4 -1
- package/shared/vault.ts +127 -0
|
@@ -4,7 +4,7 @@ import { ScrollView } from "@getpaseo/plugin/client/ui";
|
|
|
4
4
|
import type { OfficeAgent } from "../shared/contracts.js";
|
|
5
5
|
import { dotTone, type DotTone } from "../shared/model.js";
|
|
6
6
|
import { ActionButton } from "./action-button.js";
|
|
7
|
-
import { OpenTimelineContext } from "./timeline-open.js";
|
|
7
|
+
import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
|
|
8
8
|
import {
|
|
9
9
|
feedCards,
|
|
10
10
|
feedStore,
|
|
@@ -226,6 +226,7 @@ export function ActivityPanel({ office, styles, link, layout }: ColumnPanelProps
|
|
|
226
226
|
const problem = loadProblem(subscription);
|
|
227
227
|
// What the agents did before now: the lanes, their replay and the week.
|
|
228
228
|
const openTimeline = useContext(OpenTimelineContext);
|
|
229
|
+
const openHistory = useContext(OpenHistoryContext);
|
|
229
230
|
return (
|
|
230
231
|
<View style={styles.screen}>
|
|
231
232
|
<ScrollView contentContainerStyle={styles.panelFeed}>
|
|
@@ -250,6 +251,14 @@ export function ActivityPanel({ office, styles, link, layout }: ColumnPanelProps
|
|
|
250
251
|
styles={styles}
|
|
251
252
|
/>
|
|
252
253
|
) : null}
|
|
254
|
+
{openHistory ? (
|
|
255
|
+
<ActionButton
|
|
256
|
+
label="History"
|
|
257
|
+
pendingLabel="History"
|
|
258
|
+
onPress={openHistory}
|
|
259
|
+
styles={styles}
|
|
260
|
+
/>
|
|
261
|
+
) : null}
|
|
253
262
|
</View>
|
|
254
263
|
<View role="group" aria-label="Feed" style={styles.activityTabs}>
|
|
255
264
|
<Pill<FeedTab>
|
package/client/host-switches.tsx
CHANGED
|
@@ -33,6 +33,7 @@ type HostSetting =
|
|
|
33
33
|
| "Archive idle sessions"
|
|
34
34
|
| "Agent tools"
|
|
35
35
|
| "Streamer mode"
|
|
36
|
+
| "History vault"
|
|
36
37
|
| "Sticky notes"
|
|
37
38
|
| "Notes folder"
|
|
38
39
|
| "Time zone"
|
|
@@ -447,6 +448,11 @@ function FloorSettings({
|
|
|
447
448
|
[change],
|
|
448
449
|
);
|
|
449
450
|
const problem = saveProblem("Streamer mode");
|
|
451
|
+
const toggleVault = useCallback(
|
|
452
|
+
(next: boolean) => void change("History vault", { historyVault: next }),
|
|
453
|
+
[change],
|
|
454
|
+
);
|
|
455
|
+
const vaultProblem = saveProblem("History vault");
|
|
450
456
|
return (
|
|
451
457
|
<View style={settingsLayout.block}>
|
|
452
458
|
{stored && (
|
|
@@ -466,6 +472,24 @@ function FloorSettings({
|
|
|
466
472
|
{problem}
|
|
467
473
|
</Text>
|
|
468
474
|
)}
|
|
475
|
+
{stored && (
|
|
476
|
+
<LabeledSwitch
|
|
477
|
+
label="History vault"
|
|
478
|
+
value={stored.historyVault}
|
|
479
|
+
onChange={toggleVault}
|
|
480
|
+
styles={styles}
|
|
481
|
+
/>
|
|
482
|
+
)}
|
|
483
|
+
<Text style={styles.fieldHint}>
|
|
484
|
+
Off by default. On, the office keeps the prompts and the replies of each conversation in a
|
|
485
|
+
file on this host, readable by its owner only, so they can be searched from History after
|
|
486
|
+
the agent is gone.
|
|
487
|
+
</Text>
|
|
488
|
+
{vaultProblem && (
|
|
489
|
+
<Text accessibilityRole="alert" style={styles.actionError}>
|
|
490
|
+
{vaultProblem}
|
|
491
|
+
</Text>
|
|
492
|
+
)}
|
|
469
493
|
<SettingField
|
|
470
494
|
label="Sticky notes"
|
|
471
495
|
hint={`Your notes on the 3D whiteboard, with ; between them. Up to ${STICKY_NOTES_MAX}, ${STICKY_NOTE_MAX} characters each.`}
|
|
@@ -61,7 +61,8 @@ import { incidentsEntry } from "./incidents-text.js";
|
|
|
61
61
|
import { janitorNote, janitorRows } from "./context-text.js";
|
|
62
62
|
import { JanitorCard } from "./janitor-card.js";
|
|
63
63
|
import { TimelineCard } from "./timeline-card.js";
|
|
64
|
-
import { OpenTimelineContext } from "./timeline-open.js";
|
|
64
|
+
import { OpenHistoryContext, OpenTimelineContext } from "./timeline-open.js";
|
|
65
|
+
import { VaultCard } from "./vault-card.js";
|
|
65
66
|
import { useSshServers } from "./ssh-hosts.js";
|
|
66
67
|
import { MachineCard } from "./machine-card.js";
|
|
67
68
|
import { hostNote, memoryPercent, namedMachine, type HostNote } from "../shared/machine-text.js";
|
|
@@ -876,6 +877,7 @@ interface ViewControlsProps {
|
|
|
876
877
|
machine: Machine | null;
|
|
877
878
|
onMachine?: () => void;
|
|
878
879
|
onTimeline?: () => void;
|
|
880
|
+
onHistory?: () => void;
|
|
879
881
|
onChange(next: OfficeViewChoice): void;
|
|
880
882
|
compact: boolean;
|
|
881
883
|
touchScreen: boolean;
|
|
@@ -926,6 +928,48 @@ function HostResourceButton({
|
|
|
926
928
|
);
|
|
927
929
|
}
|
|
928
930
|
|
|
931
|
+
/** The toolbar's buttons for what was: the timeline and the history, each while it is offered. */
|
|
932
|
+
function PastButtons({
|
|
933
|
+
onTimeline,
|
|
934
|
+
onHistory,
|
|
935
|
+
size,
|
|
936
|
+
color,
|
|
937
|
+
styles,
|
|
938
|
+
}: {
|
|
939
|
+
onTimeline: (() => void) | undefined;
|
|
940
|
+
onHistory: (() => void) | undefined;
|
|
941
|
+
size: number;
|
|
942
|
+
color: string;
|
|
943
|
+
styles: OfficeStyles;
|
|
944
|
+
}) {
|
|
945
|
+
return (
|
|
946
|
+
<>
|
|
947
|
+
{onTimeline ? (
|
|
948
|
+
<PanelButton
|
|
949
|
+
label="Timeline"
|
|
950
|
+
icon="History"
|
|
951
|
+
screenId="timeline"
|
|
952
|
+
size={size}
|
|
953
|
+
color={color}
|
|
954
|
+
onOpen={onTimeline}
|
|
955
|
+
styles={styles}
|
|
956
|
+
/>
|
|
957
|
+
) : null}
|
|
958
|
+
{onHistory ? (
|
|
959
|
+
<PanelButton
|
|
960
|
+
label="History"
|
|
961
|
+
icon="Archive"
|
|
962
|
+
screenId="history"
|
|
963
|
+
size={size}
|
|
964
|
+
color={color}
|
|
965
|
+
onOpen={onHistory}
|
|
966
|
+
styles={styles}
|
|
967
|
+
/>
|
|
968
|
+
) : null}
|
|
969
|
+
</>
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
|
|
929
973
|
/** The view switch and the settings button. */
|
|
930
974
|
function ViewControls({
|
|
931
975
|
keyboardVisible,
|
|
@@ -940,6 +984,7 @@ function ViewControls({
|
|
|
940
984
|
machine,
|
|
941
985
|
onMachine,
|
|
942
986
|
onTimeline,
|
|
987
|
+
onHistory,
|
|
943
988
|
onChange,
|
|
944
989
|
compact,
|
|
945
990
|
touchScreen,
|
|
@@ -982,14 +1027,12 @@ function ViewControls({
|
|
|
982
1027
|
styles={styles}
|
|
983
1028
|
/>
|
|
984
1029
|
)}
|
|
985
|
-
{sidebars
|
|
986
|
-
<
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
screenId="timeline"
|
|
1030
|
+
{sidebars ? (
|
|
1031
|
+
<PastButtons
|
|
1032
|
+
onTimeline={onTimeline}
|
|
1033
|
+
onHistory={onHistory}
|
|
990
1034
|
size={touchScreen ? 20 : 16}
|
|
991
1035
|
color={color}
|
|
992
|
-
onOpen={onTimeline}
|
|
993
1036
|
styles={styles}
|
|
994
1037
|
/>
|
|
995
1038
|
) : null}
|
|
@@ -1796,23 +1839,27 @@ function OfficeContexts({
|
|
|
1796
1839
|
brand,
|
|
1797
1840
|
planUsage,
|
|
1798
1841
|
onTimeline,
|
|
1842
|
+
onHistory,
|
|
1799
1843
|
children,
|
|
1800
1844
|
}: {
|
|
1801
1845
|
brand: OfficeState["state"]["brand"];
|
|
1802
1846
|
planUsage: readonly PlanUsage[];
|
|
1803
1847
|
onTimeline: (() => void) | undefined;
|
|
1848
|
+
onHistory: (() => void) | undefined;
|
|
1804
1849
|
children: ReactNode;
|
|
1805
1850
|
}) {
|
|
1806
1851
|
return (
|
|
1807
1852
|
<OfficeBrandContext.Provider value={brand}>
|
|
1808
1853
|
<PlanUsageContext.Provider value={planUsage}>
|
|
1809
|
-
<OpenTimelineContext.Provider value={onTimeline}>
|
|
1854
|
+
<OpenTimelineContext.Provider value={onTimeline}>
|
|
1855
|
+
<OpenHistoryContext.Provider value={onHistory}>{children}</OpenHistoryContext.Provider>
|
|
1856
|
+
</OpenTimelineContext.Provider>
|
|
1810
1857
|
</PlanUsageContext.Provider>
|
|
1811
1858
|
</OfficeBrandContext.Provider>
|
|
1812
1859
|
);
|
|
1813
1860
|
}
|
|
1814
1861
|
|
|
1815
|
-
/**
|
|
1862
|
+
/** A card of the toolbar's, the timeline's or the history's: offered and shown only while the office's data is live. */
|
|
1816
1863
|
function useTimelineCard(live: boolean) {
|
|
1817
1864
|
const [open, setOpen] = useState(false);
|
|
1818
1865
|
const show = useCallback(() => setOpen(true), []);
|
|
@@ -1898,6 +1945,7 @@ export function OfficeSurface(
|
|
|
1898
1945
|
);
|
|
1899
1946
|
const planUsage = usePlanUsage(live);
|
|
1900
1947
|
const timeline = useTimelineCard(live);
|
|
1948
|
+
const history = useTimelineCard(live);
|
|
1901
1949
|
const board = useBoardSheet(model, live);
|
|
1902
1950
|
const dutyCard = useCardOpening(live);
|
|
1903
1951
|
// Until the host sends its duty list (an older host has none) nothing offers the duty board.
|
|
@@ -2116,6 +2164,7 @@ export function OfficeSurface(
|
|
|
2116
2164
|
machine={machine}
|
|
2117
2165
|
onMachine={hostEntry?.onOpen}
|
|
2118
2166
|
onTimeline={timeline.onOpen}
|
|
2167
|
+
onHistory={history.onOpen}
|
|
2119
2168
|
onChange={changeView}
|
|
2120
2169
|
compact={compact}
|
|
2121
2170
|
touchScreen={touchScreen}
|
|
@@ -2247,6 +2296,7 @@ export function OfficeSurface(
|
|
|
2247
2296
|
onClose={closeMachine}
|
|
2248
2297
|
/>
|
|
2249
2298
|
<TimelineCard open={timeline.open} styles={styles} onClose={timeline.close} />
|
|
2299
|
+
<VaultCard open={history.open} styles={styles} onClose={history.close} />
|
|
2250
2300
|
<JanitorCard
|
|
2251
2301
|
rows={contexts}
|
|
2252
2302
|
open={janitorOpen && live}
|
|
@@ -2357,7 +2407,12 @@ export function OfficeSurface(
|
|
|
2357
2407
|
</View>
|
|
2358
2408
|
);
|
|
2359
2409
|
return (
|
|
2360
|
-
<OfficeContexts
|
|
2410
|
+
<OfficeContexts
|
|
2411
|
+
brand={office.state.brand}
|
|
2412
|
+
planUsage={planUsage}
|
|
2413
|
+
onTimeline={timeline.onOpen}
|
|
2414
|
+
onHistory={history.onOpen}
|
|
2415
|
+
>
|
|
2361
2416
|
<OfficeDialogs fullscreen={full.integrated} theme={theme} styles={styles}>
|
|
2362
2417
|
{surface}
|
|
2363
2418
|
</OfficeDialogs>
|
package/client/timeline-open.ts
CHANGED
|
@@ -2,3 +2,6 @@ import { createContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
/** Opens the Timeline card; absent while the office's data is not live. */
|
|
4
4
|
export const OpenTimelineContext = createContext<(() => void) | undefined>(undefined);
|
|
5
|
+
|
|
6
|
+
/** Opens the History card; absent while the office's data is not live. */
|
|
7
|
+
export const OpenHistoryContext = createContext<(() => void) | undefined>(undefined);
|
|
@@ -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
|
@@ -516,6 +516,25 @@ 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
|
+
## 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
|
+
|
|
519
538
|
## Streamer mode, graphics and sticky notes
|
|
520
539
|
|
|
521
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, timelineFile } 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,14 @@ 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";
|
|
48
56
|
import {
|
|
49
57
|
TIMELINE_KEEP_MS,
|
|
50
58
|
TimelineFileSchema,
|
|
@@ -120,6 +128,9 @@ import {
|
|
|
120
128
|
notesModesRpc,
|
|
121
129
|
planUsageRpc,
|
|
122
130
|
timelineRpc,
|
|
131
|
+
vaultReportRpc,
|
|
132
|
+
vaultSearchRpc,
|
|
133
|
+
vaultTalkRpc,
|
|
123
134
|
teamRenameRpc,
|
|
124
135
|
trackersSaveRpc,
|
|
125
136
|
trackersTestRpc,
|
|
@@ -159,6 +170,8 @@ export interface OfficePluginDeps {
|
|
|
159
170
|
tenureFile: LifeFile<TenureLedger>;
|
|
160
171
|
/** Where the timeline is kept; without it the timeline lasts as long as the server. */
|
|
161
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>;
|
|
162
175
|
liftFile: LifeFile<LiftKept>;
|
|
163
176
|
/** The owner's duty list. */
|
|
164
177
|
dutiesFile: LifeFile<DutiesFile>;
|
|
@@ -237,6 +250,35 @@ export function createOfficePlugin(
|
|
|
237
250
|
deps.timelineFile === undefined
|
|
238
251
|
? null
|
|
239
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)}`));
|
|
240
282
|
let stopTimeline: (() => void) | undefined;
|
|
241
283
|
const timelineReady = (async () => {
|
|
242
284
|
const kept = (await deps.timelineFile?.load()) ?? null;
|
|
@@ -470,6 +512,7 @@ export function createOfficePlugin(
|
|
|
470
512
|
function settingsUnreadable(reason: string): void {
|
|
471
513
|
agentToolsOn = false;
|
|
472
514
|
stepsNamed = false;
|
|
515
|
+
vaultOn = false;
|
|
473
516
|
office.setPickupEnabled(false);
|
|
474
517
|
const message = `The office's settings cannot be read: ${reason}`;
|
|
475
518
|
log(`[office] ${message}`);
|
|
@@ -490,6 +533,7 @@ export function createOfficePlugin(
|
|
|
490
533
|
hub.setBrand(hostBrand(state.values, deps.env));
|
|
491
534
|
agentToolsOn = state.values.agentTools;
|
|
492
535
|
stepsNamed = !state.values.streamerMode;
|
|
536
|
+
vaultOn = state.values.historyVault;
|
|
493
537
|
office.setPickupEnabled(agentToolsOn && holder.held());
|
|
494
538
|
weather.settingsChanged(state.values);
|
|
495
539
|
await notesSchedule.sync(state.values);
|
|
@@ -699,6 +743,19 @@ export function createOfficePlugin(
|
|
|
699
743
|
const start = Math.max(from, end - TIMELINE_KEEP_MS);
|
|
700
744
|
return { ok: true as const, timeline: timeline.read(start, end) };
|
|
701
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
|
+
});
|
|
702
759
|
server.handle(planUsageRpc, async (_input, context) => {
|
|
703
760
|
holder.remember(context.paseo);
|
|
704
761
|
try {
|
|
@@ -917,6 +974,8 @@ export function createOfficePlugin(
|
|
|
917
974
|
await lifeReady;
|
|
918
975
|
stopLife?.();
|
|
919
976
|
stopTimeline?.();
|
|
977
|
+
stopVault?.();
|
|
978
|
+
await vaultSaves?.flush();
|
|
920
979
|
await timelineSaves?.flush();
|
|
921
980
|
for (const close of listeners.values()) close();
|
|
922
981
|
await Promise.all([tenureSaves.flush(), liftSaved]);
|
|
@@ -949,6 +1008,7 @@ export default function contribute(server: PluginServerContext): () => Promise<v
|
|
|
949
1008
|
}),
|
|
950
1009
|
tenureFile: createLifeFile(tenureFile(process.env, homedir()), TenureLedgerSchema),
|
|
951
1010
|
timelineFile: createLifeFile(timelineFile(process.env, homedir()), TimelineFileSchema),
|
|
1011
|
+
vaultFile: createLifeFile(vaultFile(process.env, homedir()), VaultFileSchema),
|
|
952
1012
|
liftFile: createLifeFile(liftFile(process.env, homedir()), LiftKeptSchema),
|
|
953
1013
|
dutiesFile: dutiesFileStore(dutiesFile(process.env, homedir()), { now: () => Date.now(), log }),
|
|
954
1014
|
chatStore: createChatStore({
|
package/package.json
CHANGED
package/server/paths.ts
CHANGED
|
@@ -81,6 +81,11 @@ export function timelineFile(env: NodeJS.ProcessEnv, home: string) {
|
|
|
81
81
|
return join(officeDir(env, home), "timeline.json");
|
|
82
82
|
}
|
|
83
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
|
+
|
|
84
89
|
export function tenureFile(env: NodeJS.ProcessEnv, home: string) {
|
|
85
90
|
return join(officeDir(env, home), "tenure.json");
|
|
86
91
|
}
|
package/server/vault.ts
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { OfficeAgent } from "../shared/contracts.js";
|
|
3
|
+
import { agentTitle } from "../shared/model.js";
|
|
4
|
+
import { LOBBY } from "../shared/names.js";
|
|
5
|
+
import {
|
|
6
|
+
VAULT_HITS_MAX,
|
|
7
|
+
VAULT_MESSAGES_MAX,
|
|
8
|
+
VAULT_TALKS_MAX,
|
|
9
|
+
VAULT_TEXT_MAX,
|
|
10
|
+
VaultMessageSchema,
|
|
11
|
+
promptReport,
|
|
12
|
+
searchWords,
|
|
13
|
+
snippetOf,
|
|
14
|
+
type PromptReport,
|
|
15
|
+
type VaultHit,
|
|
16
|
+
type VaultTalk,
|
|
17
|
+
} from "../shared/vault.js";
|
|
18
|
+
import { errorMessage } from "./errors.js";
|
|
19
|
+
import type { DirectoryView } from "./hub.js";
|
|
20
|
+
|
|
21
|
+
/** How many of an agent's newest timeline items are read after each of its turns. */
|
|
22
|
+
export const VAULT_TAIL_LIMIT = 80;
|
|
23
|
+
|
|
24
|
+
const TalkSchema = z.object({
|
|
25
|
+
name: z.string(),
|
|
26
|
+
team: z.string(),
|
|
27
|
+
/** The last timeline sequence number read: what comes after is new. */
|
|
28
|
+
seq: z.number(),
|
|
29
|
+
messages: z.array(VaultMessageSchema),
|
|
30
|
+
});
|
|
31
|
+
type Talk = z.output<typeof TalkSchema>;
|
|
32
|
+
|
|
33
|
+
export const VaultFileSchema = z.object({
|
|
34
|
+
version: z.literal(1),
|
|
35
|
+
talks: z.record(z.string(), TalkSchema),
|
|
36
|
+
});
|
|
37
|
+
export type VaultFile = z.output<typeof VaultFileSchema>;
|
|
38
|
+
|
|
39
|
+
/** A timeline entry as the vault reads it: when, where in the timeline, and the item. */
|
|
40
|
+
export interface VaultEntry {
|
|
41
|
+
at: number;
|
|
42
|
+
seq: number;
|
|
43
|
+
item: { type: string; text?: unknown };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface VaultPorts {
|
|
47
|
+
/** The newest entries of an agent's timeline, oldest first. */
|
|
48
|
+
tail(agentId: string): Promise<readonly VaultEntry[]>;
|
|
49
|
+
/** Whether the owner has turned the vault on; off, nothing is read or kept. */
|
|
50
|
+
on(): boolean;
|
|
51
|
+
save(file: VaultFile): void;
|
|
52
|
+
log(message: string): void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Vault {
|
|
56
|
+
/** The office as the directory reports it; an agent seen for the first time, or whose turn ended, is read. */
|
|
57
|
+
view(view: DirectoryView | null): void;
|
|
58
|
+
search(query: string): VaultHit[];
|
|
59
|
+
talk(agentId: string): VaultTalk | null;
|
|
60
|
+
/** The prompts sent since `from` against the prompt helper's rules. */
|
|
61
|
+
report(from: number): PromptReport;
|
|
62
|
+
/** Resolves when every read asked for so far has ended. */
|
|
63
|
+
settled(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function cut(text: string): string {
|
|
67
|
+
return text.length > VAULT_TEXT_MAX ? `${text.slice(0, VAULT_TEXT_MAX - 1)}…` : text;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function lastAt(talk: Talk): number {
|
|
71
|
+
return talk.messages.at(-1)?.at ?? 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* What was said in each conversation, kept on the host after the agent is gone: the prompts and
|
|
76
|
+
* the replies, not the tool calls. It reads an agent's timeline when it first sees the agent and
|
|
77
|
+
* after each of its turns, so it holds what was said while an office was open.
|
|
78
|
+
*/
|
|
79
|
+
export function createVault(ports: VaultPorts, kept: VaultFile | null): Vault {
|
|
80
|
+
const talks = new Map<string, Talk>(Object.entries(kept?.talks ?? {}));
|
|
81
|
+
const resting = new Map<string, boolean>();
|
|
82
|
+
let chain: Promise<void> = Promise.resolve();
|
|
83
|
+
|
|
84
|
+
function saved(): void {
|
|
85
|
+
if (talks.size > VAULT_TALKS_MAX) {
|
|
86
|
+
const oldest = [...talks].sort((a, b) => lastAt(a[1]) - lastAt(b[1]));
|
|
87
|
+
for (const [id] of oldest.slice(0, talks.size - VAULT_TALKS_MAX)) talks.delete(id);
|
|
88
|
+
}
|
|
89
|
+
ports.save({ version: 1, talks: Object.fromEntries(talks) });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function read(agent: OfficeAgent, team: string): Promise<void> {
|
|
93
|
+
const entries = await ports.tail(agent.id);
|
|
94
|
+
const talk = talks.get(agent.id) ?? { name: "", team, seq: -1, messages: [] };
|
|
95
|
+
let added = false;
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
const { type, text } = entry.item;
|
|
98
|
+
if (entry.seq <= talk.seq) continue;
|
|
99
|
+
talk.seq = entry.seq;
|
|
100
|
+
if ((type !== "user_message" && type !== "assistant_message") || typeof text !== "string") {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (text.trim() === "") continue;
|
|
104
|
+
const role = type === "user_message" ? "user" : "assistant";
|
|
105
|
+
talk.messages.push({ at: entry.at, role, text: cut(text) });
|
|
106
|
+
added = true;
|
|
107
|
+
}
|
|
108
|
+
if (!added) return;
|
|
109
|
+
talk.name = agentTitle(agent);
|
|
110
|
+
talk.team = team;
|
|
111
|
+
if (talk.messages.length > VAULT_MESSAGES_MAX) {
|
|
112
|
+
talk.messages = talk.messages.slice(-VAULT_MESSAGES_MAX);
|
|
113
|
+
}
|
|
114
|
+
talks.set(agent.id, talk);
|
|
115
|
+
saved();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
view(view) {
|
|
120
|
+
if (view === null || !ports.on()) {
|
|
121
|
+
// Seen again later, each agent is read again: what it said meanwhile is then new.
|
|
122
|
+
resting.clear();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const teams = new Map(view.workspaces.map((workspace) => [workspace.id, workspace.name]));
|
|
126
|
+
for (const agent of view.agents) {
|
|
127
|
+
const rests = agent.status === "idle" || agent.status === "error";
|
|
128
|
+
const before = resting.get(agent.id);
|
|
129
|
+
resting.set(agent.id, rests);
|
|
130
|
+
if (before !== undefined && !(rests && !before)) continue;
|
|
131
|
+
const team = (agent.workspaceId && teams.get(agent.workspaceId)) || LOBBY;
|
|
132
|
+
chain = chain
|
|
133
|
+
.then(() => read(agent, team))
|
|
134
|
+
.catch((error: unknown) =>
|
|
135
|
+
ports.log(`[office] history of ${agent.id}: ${errorMessage(error)}`),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
search(query) {
|
|
140
|
+
const words = searchWords(query);
|
|
141
|
+
const hits: VaultHit[] = [];
|
|
142
|
+
for (const [agentId, talk] of talks) {
|
|
143
|
+
for (const message of talk.messages) {
|
|
144
|
+
const snippet = snippetOf(message.text, words);
|
|
145
|
+
if (snippet === null) continue;
|
|
146
|
+
const { at, role } = message;
|
|
147
|
+
hits.push({ agentId, name: talk.name, team: talk.team, at, role, snippet });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return hits.sort((a, b) => b.at - a.at).slice(0, VAULT_HITS_MAX);
|
|
151
|
+
},
|
|
152
|
+
talk(agentId) {
|
|
153
|
+
const talk = talks.get(agentId);
|
|
154
|
+
if (talk === undefined) return null;
|
|
155
|
+
return { agentId, name: talk.name, team: talk.team, messages: talk.messages };
|
|
156
|
+
},
|
|
157
|
+
report(from) {
|
|
158
|
+
const prompts: string[] = [];
|
|
159
|
+
for (const talk of talks.values()) {
|
|
160
|
+
for (const message of talk.messages) {
|
|
161
|
+
if (message.role === "user" && message.at >= from) prompts.push(message.text);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return promptReport(prompts);
|
|
165
|
+
},
|
|
166
|
+
settled: () => chain,
|
|
167
|
+
};
|
|
168
|
+
}
|
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 { PromptReportSchema, VaultHitSchema, VaultTalkSchema } from "./vault.js";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
// In their own file, so code that needs only a name does not load the schemas.
|
|
9
10
|
import { ACTIVITY_KINDS, TEST_RESULTS } from "./names.js";
|
|
@@ -811,6 +812,30 @@ export const timelineRpc = defineRpc({
|
|
|
811
812
|
]),
|
|
812
813
|
});
|
|
813
814
|
|
|
815
|
+
/**
|
|
816
|
+
* The history vault. `on` false means the owner has it off: nothing is kept and nothing found.
|
|
817
|
+
* A search answers with the newest messages that hold every word of the query.
|
|
818
|
+
*/
|
|
819
|
+
export const vaultSearchRpc = defineRpc({
|
|
820
|
+
name: "office.vault.search.request",
|
|
821
|
+
input: z.object({ query: z.string().max(200) }),
|
|
822
|
+
output: z.object({ on: z.boolean(), hits: z.array(VaultHitSchema) }),
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
/** One kept conversation; null when the vault has none for this agent. */
|
|
826
|
+
export const vaultTalkRpc = defineRpc({
|
|
827
|
+
name: "office.vault.talk.request",
|
|
828
|
+
input: z.object({ agentId: z.string() }),
|
|
829
|
+
output: z.object({ talk: VaultTalkSchema.nullable() }),
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
/** The last seven days' prompts against the prompt helper's rules, worked out on the host. */
|
|
833
|
+
export const vaultReportRpc = defineRpc({
|
|
834
|
+
name: "office.vault.report.request",
|
|
835
|
+
input: z.object({}),
|
|
836
|
+
output: z.object({ on: z.boolean(), report: PromptReportSchema }),
|
|
837
|
+
});
|
|
838
|
+
|
|
814
839
|
export const WriterModesSchema = z.object({
|
|
815
840
|
/** The provider the writer would start on now, by its label. */
|
|
816
841
|
provider: z.string(),
|
package/shared/settings.ts
CHANGED
|
@@ -77,6 +77,7 @@ const HostValuesSchema = z.object({
|
|
|
77
77
|
// A plan this build does not know (a later build's, or a hand edit) reads as the company floor.
|
|
78
78
|
floorPlan: z.enum(FLOOR_PLANS).default("pro").catch("pro"),
|
|
79
79
|
streamerMode: z.boolean().default(true),
|
|
80
|
+
historyVault: z.boolean().default(false),
|
|
80
81
|
stickyNotes: z.string().max(STICKY_NOTES_TEXT_MAX).default(""),
|
|
81
82
|
jiraProjects: z.string().default(""),
|
|
82
83
|
sentryOrg: z.string().default(""),
|
|
@@ -143,7 +144,9 @@ const SUNDAY_TO_THURSDAY = [0, 1, 2, 3, 4];
|
|
|
143
144
|
* the 3D floor's plan: `pro` the company floor, `cozy` one open room, or `hq` headquarters.
|
|
144
145
|
* `streamerMode` on (the default) keeps file names, commands and sites out of what the office
|
|
145
146
|
* sends to the floor; off, a person's bubble names what they are at. `stickyNotes` are the
|
|
146
|
-
* owner's notes on the 3D whiteboard, with `;` between them. `
|
|
147
|
+
* owner's notes on the 3D whiteboard, with `;` between them. `historyVault` on has the office
|
|
148
|
+
* keep what is said in each conversation in a file on the host; it is off until the owner turns
|
|
149
|
+
* it on. `jiraProjects`
|
|
147
150
|
* and `sentryProjects` are the comma separated projects checked for incidents, `sentryOrg` their
|
|
148
151
|
* Sentry organisation and `sentryUrl` the Sentry the token is sent to.
|
|
149
152
|
*/
|
package/shared/vault.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { coach } from "./upstream/prompt-coach.js";
|
|
3
|
+
|
|
4
|
+
/** The most characters of a message the vault keeps, of messages per conversation, and of conversations. */
|
|
5
|
+
export const VAULT_TEXT_MAX = 2000;
|
|
6
|
+
export const VAULT_MESSAGES_MAX = 300;
|
|
7
|
+
export const VAULT_TALKS_MAX = 200;
|
|
8
|
+
/** The most hits a search answers with: the newest. */
|
|
9
|
+
export const VAULT_HITS_MAX = 40;
|
|
10
|
+
|
|
11
|
+
export const VaultMessageSchema = z.object({
|
|
12
|
+
/** Epoch ms. */
|
|
13
|
+
at: z.number(),
|
|
14
|
+
role: z.enum(["user", "assistant"]),
|
|
15
|
+
text: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export type VaultMessage = z.output<typeof VaultMessageSchema>;
|
|
18
|
+
|
|
19
|
+
export const VaultHitSchema = z.object({
|
|
20
|
+
agentId: z.string(),
|
|
21
|
+
name: z.string(),
|
|
22
|
+
team: z.string(),
|
|
23
|
+
at: z.number(),
|
|
24
|
+
role: z.enum(["user", "assistant"]),
|
|
25
|
+
/** The words around the first match, on one line. */
|
|
26
|
+
snippet: z.string(),
|
|
27
|
+
});
|
|
28
|
+
export type VaultHit = z.output<typeof VaultHitSchema>;
|
|
29
|
+
|
|
30
|
+
export const VaultTalkSchema = z.object({
|
|
31
|
+
agentId: z.string(),
|
|
32
|
+
name: z.string(),
|
|
33
|
+
team: z.string(),
|
|
34
|
+
messages: z.array(VaultMessageSchema),
|
|
35
|
+
});
|
|
36
|
+
export type VaultTalk = z.output<typeof VaultTalkSchema>;
|
|
37
|
+
|
|
38
|
+
/** The words of a search: lower case, none empty. Every one of them has to be in a message. */
|
|
39
|
+
export function searchWords(query: string): string[] {
|
|
40
|
+
return query
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.split(/\s+/)
|
|
43
|
+
.filter((word) => word !== "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const SNIPPET_BEFORE = 50;
|
|
47
|
+
const SNIPPET_MAX = 160;
|
|
48
|
+
|
|
49
|
+
/** The text around its first match of `words`, on one line; null when a word is missing. */
|
|
50
|
+
export function snippetOf(text: string, words: readonly string[]): string | null {
|
|
51
|
+
const lower = text.toLowerCase();
|
|
52
|
+
if (words.length === 0 || !words.every((word) => lower.includes(word))) return null;
|
|
53
|
+
const at = Math.min(...words.map((word) => lower.indexOf(word)));
|
|
54
|
+
const start = Math.max(0, at - SNIPPET_BEFORE);
|
|
55
|
+
const cut = text
|
|
56
|
+
.slice(start, start + SNIPPET_MAX)
|
|
57
|
+
.replace(/\s+/g, " ")
|
|
58
|
+
.trim();
|
|
59
|
+
return `${start > 0 ? "…" : ""}${cut}${start + SNIPPET_MAX < text.length ? "…" : ""}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The prompt helper's rules a sent prompt can break; a photo's rule needs the draft, not the text. */
|
|
63
|
+
export const REPORT_RULES = ["tooShort", "vague", "dangling", "multi"] as const;
|
|
64
|
+
export type ReportRule = (typeof REPORT_RULES)[number];
|
|
65
|
+
|
|
66
|
+
export const RULE_TEXT: Readonly<Record<ReportRule, { title: string; advice: string }>> = {
|
|
67
|
+
tooShort: {
|
|
68
|
+
title: "Too short to act on",
|
|
69
|
+
advice: "Say what result you want the session to produce.",
|
|
70
|
+
},
|
|
71
|
+
vague: { title: "No way to tell when it is done", advice: "Add what done looks like." },
|
|
72
|
+
dangling: {
|
|
73
|
+
title: "Points at something it does not name",
|
|
74
|
+
advice: "Name the file, the section or the message you mean.",
|
|
75
|
+
},
|
|
76
|
+
multi: { title: "Several tasks in one message", advice: "Number the tasks, or send them apart." },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const RuleCountSchema = z.object({
|
|
80
|
+
rule: z.enum(REPORT_RULES),
|
|
81
|
+
count: z.number(),
|
|
82
|
+
/** Up to three of the prompts, cut to a line. */
|
|
83
|
+
examples: z.array(z.string()),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const PromptReportSchema = z.object({
|
|
87
|
+
/** The prompts read, and those no rule had anything to say about. */
|
|
88
|
+
total: z.number(),
|
|
89
|
+
clean: z.number(),
|
|
90
|
+
rules: z.array(RuleCountSchema),
|
|
91
|
+
});
|
|
92
|
+
export type PromptReport = z.output<typeof PromptReportSchema>;
|
|
93
|
+
|
|
94
|
+
const EXAMPLE_MAX = 90;
|
|
95
|
+
const EXAMPLES = 3;
|
|
96
|
+
|
|
97
|
+
function oneLine(text: string): string {
|
|
98
|
+
const line = text.replace(/\s+/g, " ").trim();
|
|
99
|
+
return line.length > EXAMPLE_MAX ? `${line.slice(0, EXAMPLE_MAX - 1)}…` : line;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The prompts against the prompt helper's rules: how many each rule speaks to, with examples.
|
|
104
|
+
* The helper's own code decides, word lists and all; no model reads anything.
|
|
105
|
+
*/
|
|
106
|
+
export function promptReport(prompts: readonly string[]): PromptReport {
|
|
107
|
+
const found = new Map<ReportRule, { count: number; examples: string[] }>();
|
|
108
|
+
let clean = 0;
|
|
109
|
+
for (const text of prompts) {
|
|
110
|
+
const rules = new Set<ReportRule>();
|
|
111
|
+
for (const hint of coach({ text, photos: 0, quoted: false })) {
|
|
112
|
+
if (hint.id !== "photoBare") rules.add(hint.id);
|
|
113
|
+
}
|
|
114
|
+
if (rules.size === 0) clean += 1;
|
|
115
|
+
for (const rule of rules) {
|
|
116
|
+
const entry = found.get(rule) ?? { count: 0, examples: [] };
|
|
117
|
+
entry.count += 1;
|
|
118
|
+
if (entry.examples.length < EXAMPLES) entry.examples.push(oneLine(text));
|
|
119
|
+
found.set(rule, entry);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const rules = REPORT_RULES.flatMap((rule) => {
|
|
123
|
+
const entry = found.get(rule);
|
|
124
|
+
return entry === undefined ? [] : [{ rule, ...entry }];
|
|
125
|
+
}).sort((a, b) => b.count - a.count);
|
|
126
|
+
return { total: prompts.length, clean, rules };
|
|
127
|
+
}
|