paseo-recap 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/OVERVIEW.md +41 -0
- package/README.md +140 -2
- package/client/format.ts +56 -0
- package/client/pills.tsx +161 -0
- package/client/recap-card.tsx +218 -0
- package/client/recap-line.tsx +41 -0
- package/client/settings-screen.tsx +319 -0
- package/index.client.tsx +45 -0
- package/index.server.ts +169 -0
- package/package.json +45 -4
- package/paseo-plugin.json +6 -0
- package/server/cli.ts +132 -0
- package/server/errors.ts +29 -0
- package/server/generators.ts +173 -0
- package/server/history.ts +204 -0
- package/server/json.ts +13 -0
- package/server/models.ts +135 -0
- package/server/paseo-types.ts +8 -0
- package/server/process.ts +95 -0
- package/server/prompt.ts +86 -0
- package/server/scheduler.ts +434 -0
- package/server/store.ts +117 -0
- package/server/usage.ts +61 -0
- package/shared/recap.ts +156 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { Text, View } from "react-native";
|
|
5
|
+
import type { RecapTimelineData } from "../shared/recap";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The recap as a muted line after the turn it summarizes, sized like Paseo's compaction marker.
|
|
9
|
+
* Plain text only: model output is untrusted.
|
|
10
|
+
*/
|
|
11
|
+
export function RecapLine({ item, theme }: PluginTimelineItemProps<RecapTimelineData>) {
|
|
12
|
+
const styles = useMemo(
|
|
13
|
+
() => ({
|
|
14
|
+
row: { flexDirection: "row" as const, alignItems: "flex-start" as const, gap: 8, paddingVertical: 8 },
|
|
15
|
+
icon: { height: 20, justifyContent: "center" as const },
|
|
16
|
+
body: { flex: 1, minWidth: 0 },
|
|
17
|
+
text: { color: theme.colors.foregroundMuted, fontSize: 14, lineHeight: 20 },
|
|
18
|
+
label: { color: theme.colors.foreground },
|
|
19
|
+
}),
|
|
20
|
+
[theme],
|
|
21
|
+
);
|
|
22
|
+
const { summary, nextAction } = item.data;
|
|
23
|
+
return (
|
|
24
|
+
<View style={styles.row} accessibilityLabel={`Recap: ${summary}${nextAction ? ` Next: ${nextAction}` : ""}`}>
|
|
25
|
+
<View style={styles.icon}>
|
|
26
|
+
<Icon name="ScrollText" size={14} color={theme.colors.foregroundMuted} />
|
|
27
|
+
</View>
|
|
28
|
+
<View style={styles.body}>
|
|
29
|
+
<Text style={styles.text} selectable>
|
|
30
|
+
{summary}
|
|
31
|
+
</Text>
|
|
32
|
+
{nextAction ? (
|
|
33
|
+
<Text style={styles.text} selectable>
|
|
34
|
+
<Text style={styles.label}>Next: </Text>
|
|
35
|
+
{nextAction}
|
|
36
|
+
</Text>
|
|
37
|
+
) : null}
|
|
38
|
+
</View>
|
|
39
|
+
</View>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { useRpc, useSettings, type PluginSurfaceProps, type SettingsState } from "@getpaseo/plugin/client";
|
|
2
|
+
import {
|
|
3
|
+
SettingsAction,
|
|
4
|
+
SettingsCard,
|
|
5
|
+
SettingsInput,
|
|
6
|
+
SettingsRow,
|
|
7
|
+
SettingsSection,
|
|
8
|
+
SettingsSelect,
|
|
9
|
+
SettingsSwitch,
|
|
10
|
+
} from "@getpaseo/plugin/client/ui";
|
|
11
|
+
import { useQuery } from "@tanstack/react-query";
|
|
12
|
+
import { useEffect, useRef, useState } from "react";
|
|
13
|
+
import { Text } from "react-native";
|
|
14
|
+
import {
|
|
15
|
+
MODEL_ID_PATTERN,
|
|
16
|
+
recapModelPlanRpc,
|
|
17
|
+
recapSettings,
|
|
18
|
+
SETTING_RANGES,
|
|
19
|
+
type GeneratorChoice,
|
|
20
|
+
isRecapProvider,
|
|
21
|
+
RECAP_PROVIDERS,
|
|
22
|
+
type GeneratorMode,
|
|
23
|
+
type RecapProvider,
|
|
24
|
+
type RecapSettings,
|
|
25
|
+
} from "../shared/recap";
|
|
26
|
+
import { describePlan } from "./format";
|
|
27
|
+
|
|
28
|
+
/** Typing pauses this long before a valid value is saved, so each keystroke is not a save. */
|
|
29
|
+
const SAVE_DELAY_MS = 600;
|
|
30
|
+
|
|
31
|
+
type ReadySettings = Extract<SettingsState<typeof recapSettings.schema>, { status: "ready" }>;
|
|
32
|
+
type Save = (patch: Partial<RecapSettings>) => void;
|
|
33
|
+
|
|
34
|
+
type ModelSource = GeneratorMode | RecapProvider;
|
|
35
|
+
|
|
36
|
+
const MODEL_SOURCE_OPTIONS: ReadonlyArray<{ label: string; value: ModelSource }> = [
|
|
37
|
+
{ label: "Same as agent", value: "auto" },
|
|
38
|
+
{ label: "Metadata model", value: "metadata" },
|
|
39
|
+
...Object.entries(RECAP_PROVIDERS).map(([value, { label }]) => ({ label, value: value as RecapProvider })),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const MODE_HINTS: Record<GeneratorMode, string> = {
|
|
43
|
+
auto: "Recaps use the agent's own provider when it has a small model, so the conversation stays with the vendor you chose. Otherwise they pick a model the way Paseo's Metadata generation does.",
|
|
44
|
+
metadata:
|
|
45
|
+
"Recaps pick a model the way Paseo's Metadata generation does: the models set there, then Paseo's small models that are installed.",
|
|
46
|
+
};
|
|
47
|
+
const CLI_HINT = " Runs the provider's CLI on this computer with your existing login.";
|
|
48
|
+
|
|
49
|
+
function modelSourceHint(source: ModelSource): string {
|
|
50
|
+
const hint = isRecapProvider(source) ? `Recaps always use ${RECAP_PROVIDERS[source].label}.` : MODE_HINTS[source];
|
|
51
|
+
return hint + CLI_HINT;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function modelSource(generator: RecapSettings["generator"]): ModelSource {
|
|
55
|
+
if (typeof generator === "string") return generator;
|
|
56
|
+
return isRecapProvider(generator.provider) ? generator.provider : "auto";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A provider without a model name uses its small model from Paseo's list, or the CLI default. */
|
|
60
|
+
function generatorFor(source: ModelSource): GeneratorMode | GeneratorChoice {
|
|
61
|
+
return isRecapProvider(source) ? { provider: source } : source;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A text field that saves once its value is valid and typing pauses. Invalid text stays in the
|
|
66
|
+
* field with an explanation and is never saved.
|
|
67
|
+
*/
|
|
68
|
+
function ValidatedInput({
|
|
69
|
+
label,
|
|
70
|
+
hint,
|
|
71
|
+
initialValue,
|
|
72
|
+
placeholder,
|
|
73
|
+
disabled,
|
|
74
|
+
parse,
|
|
75
|
+
onValid,
|
|
76
|
+
}: {
|
|
77
|
+
label: string;
|
|
78
|
+
hint: string;
|
|
79
|
+
initialValue: string;
|
|
80
|
+
placeholder?: string;
|
|
81
|
+
disabled: boolean;
|
|
82
|
+
/** Returns the value to save, or an error message. */
|
|
83
|
+
parse(text: string): { value: string } | { error: string };
|
|
84
|
+
onValid(value: string): void;
|
|
85
|
+
}) {
|
|
86
|
+
const [error, setError] = useState<string | null>(null);
|
|
87
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
88
|
+
useEffect(
|
|
89
|
+
() => () => {
|
|
90
|
+
if (timer.current) clearTimeout(timer.current);
|
|
91
|
+
},
|
|
92
|
+
[],
|
|
93
|
+
);
|
|
94
|
+
const onChangeText = (text: string) => {
|
|
95
|
+
if (timer.current) clearTimeout(timer.current);
|
|
96
|
+
const result = parse(text);
|
|
97
|
+
if ("error" in result) {
|
|
98
|
+
setError(result.error);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setError(null);
|
|
102
|
+
timer.current = setTimeout(() => onValid(result.value), SAVE_DELAY_MS);
|
|
103
|
+
};
|
|
104
|
+
return (
|
|
105
|
+
<SettingsInput
|
|
106
|
+
label={label}
|
|
107
|
+
hint={hint}
|
|
108
|
+
initialValue={initialValue}
|
|
109
|
+
placeholder={placeholder}
|
|
110
|
+
disabled={disabled}
|
|
111
|
+
error={error}
|
|
112
|
+
onChangeText={onChangeText}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function NumberInput({
|
|
118
|
+
setting,
|
|
119
|
+
label,
|
|
120
|
+
hint,
|
|
121
|
+
values,
|
|
122
|
+
disabled,
|
|
123
|
+
save,
|
|
124
|
+
}: {
|
|
125
|
+
setting: keyof typeof SETTING_RANGES;
|
|
126
|
+
label: string;
|
|
127
|
+
hint: string;
|
|
128
|
+
values: RecapSettings;
|
|
129
|
+
disabled: boolean;
|
|
130
|
+
save: Save;
|
|
131
|
+
}) {
|
|
132
|
+
const { min, max } = SETTING_RANGES[setting];
|
|
133
|
+
const current = values[setting];
|
|
134
|
+
return (
|
|
135
|
+
<ValidatedInput
|
|
136
|
+
label={label}
|
|
137
|
+
hint={`${hint} ${min}–${max}.`}
|
|
138
|
+
initialValue={String(current)}
|
|
139
|
+
disabled={disabled}
|
|
140
|
+
parse={(text) => {
|
|
141
|
+
const trimmed = text.trim();
|
|
142
|
+
const value = Number(trimmed);
|
|
143
|
+
if (!/^\d+$/.test(trimmed) || value < min || value > max) {
|
|
144
|
+
return { error: `Enter a whole number from ${min} to ${max}.` };
|
|
145
|
+
}
|
|
146
|
+
return { value: String(value) };
|
|
147
|
+
}}
|
|
148
|
+
onValid={(value) => {
|
|
149
|
+
if (Number(value) !== current) save({ [setting]: Number(value) });
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function RecapSettingsForm({ settings }: { settings: ReadySettings }) {
|
|
156
|
+
const { values } = settings;
|
|
157
|
+
// Debounced saves fire after later renders; always write onto the latest document.
|
|
158
|
+
const latest = useRef(settings);
|
|
159
|
+
latest.current = settings;
|
|
160
|
+
const save: Save = (patch) => {
|
|
161
|
+
const { values: currentValues, revision } = latest.current;
|
|
162
|
+
void latest.current.save({ ...currentValues, ...patch }, revision);
|
|
163
|
+
};
|
|
164
|
+
// Text fields stay editable while saving; locking them would interrupt typing.
|
|
165
|
+
const disabled = settings.saving;
|
|
166
|
+
const autoDisabled = disabled || !values.autoRecap;
|
|
167
|
+
const autoInputDisabled = !values.autoRecap;
|
|
168
|
+
const source = modelSource(values.generator);
|
|
169
|
+
const model = typeof values.generator === "string" ? "" : (values.generator.model ?? "");
|
|
170
|
+
const getModelPlan = useRpc(recapModelPlanRpc);
|
|
171
|
+
const plan = useQuery({
|
|
172
|
+
queryKey: ["paseo-recap", "models", values.generator],
|
|
173
|
+
queryFn: () => getModelPlan({ generator: values.generator }),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<>
|
|
178
|
+
<SettingsSection title="Automatic recaps">
|
|
179
|
+
<SettingsCard>
|
|
180
|
+
<SettingsSwitch
|
|
181
|
+
label="Generate recaps automatically"
|
|
182
|
+
hint="/paseo-recap and the pill always work."
|
|
183
|
+
value={values.autoRecap}
|
|
184
|
+
disabled={disabled}
|
|
185
|
+
onValueChange={(autoRecap) => save({ autoRecap })}
|
|
186
|
+
/>
|
|
187
|
+
<NumberInput
|
|
188
|
+
setting="turnsBetweenRecaps"
|
|
189
|
+
label="Every N turns"
|
|
190
|
+
hint="Completed turns between recaps; 1 recaps after every turn."
|
|
191
|
+
values={values}
|
|
192
|
+
disabled={autoInputDisabled}
|
|
193
|
+
save={save}
|
|
194
|
+
/>
|
|
195
|
+
<NumberInput
|
|
196
|
+
setting="idleDelaySeconds"
|
|
197
|
+
label="Wait after a turn (seconds)"
|
|
198
|
+
hint="If you reply sooner, that turn is not recapped."
|
|
199
|
+
values={values}
|
|
200
|
+
disabled={autoInputDisabled}
|
|
201
|
+
save={save}
|
|
202
|
+
/>
|
|
203
|
+
<NumberInput
|
|
204
|
+
setting="minTurns"
|
|
205
|
+
label="Start after (messages)"
|
|
206
|
+
hint="Your messages before a session gets its first recap."
|
|
207
|
+
values={values}
|
|
208
|
+
disabled={autoInputDisabled}
|
|
209
|
+
save={save}
|
|
210
|
+
/>
|
|
211
|
+
<SettingsSwitch
|
|
212
|
+
label="Recap subagents"
|
|
213
|
+
hint="Also recap agents that other agents start."
|
|
214
|
+
value={values.includeSubagents}
|
|
215
|
+
disabled={autoDisabled}
|
|
216
|
+
onValueChange={(includeSubagents) => save({ includeSubagents })}
|
|
217
|
+
/>
|
|
218
|
+
<SettingsSwitch
|
|
219
|
+
label="Wait for subagents"
|
|
220
|
+
hint="Hold an agent's recap while its subagents run, up to 10 minutes."
|
|
221
|
+
value={values.waitForSubagents}
|
|
222
|
+
disabled={autoDisabled}
|
|
223
|
+
onValueChange={(waitForSubagents) => save({ waitForSubagents })}
|
|
224
|
+
/>
|
|
225
|
+
</SettingsCard>
|
|
226
|
+
</SettingsSection>
|
|
227
|
+
<SettingsSection title="Recap content">
|
|
228
|
+
<SettingsCard>
|
|
229
|
+
<NumberInput
|
|
230
|
+
setting="historyExchanges"
|
|
231
|
+
label="Recent exchanges to read"
|
|
232
|
+
hint="Each is one of your messages and the reply. Text only, within about 8,000 tokens; the oldest are dropped first."
|
|
233
|
+
values={values}
|
|
234
|
+
disabled={false}
|
|
235
|
+
save={save}
|
|
236
|
+
/>
|
|
237
|
+
</SettingsCard>
|
|
238
|
+
</SettingsSection>
|
|
239
|
+
<SettingsSection title="Model">
|
|
240
|
+
<SettingsCard>
|
|
241
|
+
<SettingsSelect
|
|
242
|
+
label="Recap model"
|
|
243
|
+
hint={modelSourceHint(source)}
|
|
244
|
+
value={source}
|
|
245
|
+
options={MODEL_SOURCE_OPTIONS}
|
|
246
|
+
disabled={disabled}
|
|
247
|
+
onValueChange={(next) => save({ generator: generatorFor(next) })}
|
|
248
|
+
/>
|
|
249
|
+
{source === "auto" || source === "metadata" ? null : (
|
|
250
|
+
<ValidatedInput
|
|
251
|
+
// Remount per provider so the field shows the newly selected provider's model.
|
|
252
|
+
key={source}
|
|
253
|
+
label="Model name"
|
|
254
|
+
hint="Any model id the CLI accepts. Leave empty for the provider's small model from Paseo's list, or the CLI's default."
|
|
255
|
+
initialValue={model}
|
|
256
|
+
placeholder="Small model"
|
|
257
|
+
disabled={false}
|
|
258
|
+
parse={(text) => {
|
|
259
|
+
const trimmed = text.trim();
|
|
260
|
+
if (trimmed !== "" && (trimmed.length > 200 || !MODEL_ID_PATTERN.test(trimmed))) {
|
|
261
|
+
return { error: "Use letters, digits, and . _ : / @ + - only, without spaces." };
|
|
262
|
+
}
|
|
263
|
+
return { value: trimmed };
|
|
264
|
+
}}
|
|
265
|
+
onValid={(next) => {
|
|
266
|
+
if (next !== model) {
|
|
267
|
+
save({ generator: next === "" ? { provider: source } : { provider: source, model: next } });
|
|
268
|
+
}
|
|
269
|
+
}}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
<SettingsRow
|
|
273
|
+
label="Will use"
|
|
274
|
+
hint={
|
|
275
|
+
plan.data
|
|
276
|
+
? describePlan(plan.data)
|
|
277
|
+
: plan.isError
|
|
278
|
+
? "Could not read Paseo's model settings."
|
|
279
|
+
: "Checking…"
|
|
280
|
+
}
|
|
281
|
+
/>
|
|
282
|
+
</SettingsCard>
|
|
283
|
+
</SettingsSection>
|
|
284
|
+
{settings.saveError ? (
|
|
285
|
+
<SettingsSection title="Error">
|
|
286
|
+
<SettingsCard>
|
|
287
|
+
<SettingsRow label="Could not save settings" error={settings.saveError} />
|
|
288
|
+
</SettingsCard>
|
|
289
|
+
</SettingsSection>
|
|
290
|
+
) : null}
|
|
291
|
+
</>
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export function RecapSettingsScreen({ theme }: PluginSurfaceProps) {
|
|
296
|
+
const settings = useSettings(recapSettings);
|
|
297
|
+
|
|
298
|
+
if (settings.status === "loading") {
|
|
299
|
+
return <Text style={{ color: theme.colors.foregroundMuted }}>Loading…</Text>;
|
|
300
|
+
}
|
|
301
|
+
if (settings.status === "error") {
|
|
302
|
+
return <Text style={{ color: theme.colors.statusDanger }}>Could not load settings.</Text>;
|
|
303
|
+
}
|
|
304
|
+
if (settings.status === "invalid") {
|
|
305
|
+
return (
|
|
306
|
+
<SettingsSection title="Recap">
|
|
307
|
+
<SettingsCard>
|
|
308
|
+
<SettingsAction
|
|
309
|
+
label="Stored settings are invalid"
|
|
310
|
+
hint={settings.error}
|
|
311
|
+
actionLabel="Reset to defaults"
|
|
312
|
+
onPress={() => void settings.reset()}
|
|
313
|
+
/>
|
|
314
|
+
</SettingsCard>
|
|
315
|
+
</SettingsSection>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
return <RecapSettingsForm settings={settings} />;
|
|
319
|
+
}
|
package/index.client.tsx
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { RecapLine } from "./client/recap-line";
|
|
3
|
+
import { RecapPills } from "./client/pills";
|
|
4
|
+
import { RecapSettingsScreen } from "./client/settings-screen";
|
|
5
|
+
import { RECAP_TIMELINE_KIND, RecapTimelineDataSchema, recapRegenerateRpc } from "./shared/recap";
|
|
6
|
+
|
|
7
|
+
export default function contribute(client: PluginClientContext) {
|
|
8
|
+
const pills = new RecapPills(client);
|
|
9
|
+
pills.start();
|
|
10
|
+
|
|
11
|
+
const removeTimelineRenderer = client.addTimelineRenderer({
|
|
12
|
+
kind: RECAP_TIMELINE_KIND,
|
|
13
|
+
version: 1,
|
|
14
|
+
schema: RecapTimelineDataSchema,
|
|
15
|
+
Component: RecapLine,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const removeSettings = client.addSettingsScreen({
|
|
19
|
+
id: "recap",
|
|
20
|
+
title: "Recap",
|
|
21
|
+
icon: "ScrollText",
|
|
22
|
+
Component: RecapSettingsScreen,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const removeCommand = client.addSlashCommand({
|
|
26
|
+
// Not "recap": plugin commands take precedence over provider commands, and Claude Code agents
|
|
27
|
+
// already offer their own /recap.
|
|
28
|
+
name: "paseo-recap",
|
|
29
|
+
description: "Summarize where this agent stands",
|
|
30
|
+
argumentHint: "",
|
|
31
|
+
context: "agent",
|
|
32
|
+
async onSubmit({ agent, rpc }) {
|
|
33
|
+
// The pill shows progress; the RPC resolves once the recap is written.
|
|
34
|
+
const view = await pills.track(agent.id, rpc(recapRegenerateRpc, { agentId: agent.id }));
|
|
35
|
+
if (view.error) throw new Error(view.error);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
removeTimelineRenderer();
|
|
41
|
+
removeSettings();
|
|
42
|
+
removeCommand();
|
|
43
|
+
pills.stop();
|
|
44
|
+
};
|
|
45
|
+
}
|
package/index.server.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
recapGetRpc,
|
|
7
|
+
recapListRpc,
|
|
8
|
+
recapModelPlanRpc,
|
|
9
|
+
recapRegenerateRpc,
|
|
10
|
+
RECAP_TIMELINE_KIND,
|
|
11
|
+
recapSettings,
|
|
12
|
+
type RecapSettings,
|
|
13
|
+
type RecapTimelineData,
|
|
14
|
+
} from "./shared/recap";
|
|
15
|
+
import { errorMessage, RecapSkippedError } from "./server/errors";
|
|
16
|
+
import { RecapGenerator } from "./server/generators";
|
|
17
|
+
import { describeModelPlan, resolveCandidates, type GeneratorInputs } from "./server/models";
|
|
18
|
+
import type { PaseoApi } from "./server/paseo-types";
|
|
19
|
+
import { runProcess } from "./server/process";
|
|
20
|
+
import { RecapScheduler } from "./server/scheduler";
|
|
21
|
+
import { RecapStore } from "./server/store";
|
|
22
|
+
import { UsageGuard } from "./server/usage";
|
|
23
|
+
|
|
24
|
+
const TIMELINE_FETCH_LIMIT = 500;
|
|
25
|
+
|
|
26
|
+
function log(message: string, detail?: unknown): void {
|
|
27
|
+
if (detail === undefined) console.error(`[paseo-recap] ${message}`);
|
|
28
|
+
else console.error(`[paseo-recap] ${message}:`, detail);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function storePath(): string {
|
|
32
|
+
const paseoHome = process.env.PASEO_HOME ?? join(homedir(), ".paseo");
|
|
33
|
+
return join(paseoHome, "plugin-data", "paseo-recap", "recaps.json");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default function contribute(server: PluginServerContext) {
|
|
37
|
+
const settings = server.registerSettings(recapSettings);
|
|
38
|
+
const store = new RecapStore(storePath(), log);
|
|
39
|
+
const tempRoot = join(tmpdir(), "paseo-recap");
|
|
40
|
+
const generator = new RecapGenerator({ runProcess, env: process.env, tempRoot, now: Date.now, log });
|
|
41
|
+
const usage = new UsageGuard(
|
|
42
|
+
async () => (await requirePaseo().providers.listUsage()).providers,
|
|
43
|
+
Date.now,
|
|
44
|
+
log,
|
|
45
|
+
);
|
|
46
|
+
// The API handle arrives with hook and RPC contexts; timers fire later and reuse the latest one.
|
|
47
|
+
let paseo: PaseoApi | null = null;
|
|
48
|
+
const requirePaseo = (): PaseoApi => {
|
|
49
|
+
if (!paseo) throw new Error("Paseo API is not available yet");
|
|
50
|
+
return paseo;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const readGeneratorInputs = async (api: PaseoApi): Promise<GeneratorInputs> => {
|
|
54
|
+
const [{ config }, { entries }] = await Promise.all([api.config.get(), api.providers.snapshot()]);
|
|
55
|
+
return {
|
|
56
|
+
config: { metadataGeneration: config.metadataGeneration, providers: config.providers },
|
|
57
|
+
providers: entries,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const readSettings = async (): Promise<RecapSettings> => {
|
|
62
|
+
const state = await settings.read();
|
|
63
|
+
if (state.status === "ready") return state.values;
|
|
64
|
+
log("settings are invalid; using defaults", state.error);
|
|
65
|
+
return recapSettings.schema.parse({});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const scheduler = new RecapScheduler({
|
|
69
|
+
store,
|
|
70
|
+
readSettings,
|
|
71
|
+
log,
|
|
72
|
+
async generate(prompt, signal, { agentProvider, trigger }) {
|
|
73
|
+
const [inputs, current] = await Promise.all([readGeneratorInputs(requirePaseo()), readSettings()]);
|
|
74
|
+
let candidates = resolveCandidates(current.generator, inputs, agentProvider);
|
|
75
|
+
if (trigger === "auto" && candidates.length > 0) {
|
|
76
|
+
const nearLimit = await usage.nearLimit();
|
|
77
|
+
const allowed = candidates.filter((candidate) => !nearLimit.has(candidate.provider));
|
|
78
|
+
if (allowed.length === 0) throw new RecapSkippedError("recap models are near their usage limit");
|
|
79
|
+
candidates = allowed;
|
|
80
|
+
}
|
|
81
|
+
return generator.generate(prompt, candidates, signal);
|
|
82
|
+
},
|
|
83
|
+
async fetchAgentContext(agentId) {
|
|
84
|
+
const payload = await requirePaseo().agents.ref(agentId).timeline.refetch({
|
|
85
|
+
direction: "tail",
|
|
86
|
+
projection: "canonical",
|
|
87
|
+
limit: TIMELINE_FETCH_LIMIT,
|
|
88
|
+
});
|
|
89
|
+
if (payload.error) throw new Error(payload.error);
|
|
90
|
+
return {
|
|
91
|
+
timeline: payload.entries.map((entry) => entry.item),
|
|
92
|
+
title: payload.agent?.title ?? null,
|
|
93
|
+
workspaceId: payload.agent?.workspaceId ?? null,
|
|
94
|
+
provider: payload.agent?.provider ?? null,
|
|
95
|
+
running: payload.agent?.status === "running",
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
async publish(recap) {
|
|
99
|
+
const data: RecapTimelineData = { summary: recap.summary, nextAction: recap.nextAction };
|
|
100
|
+
await requirePaseo().agents.ref(recap.agentId).timeline.append({
|
|
101
|
+
type: "plugin",
|
|
102
|
+
// One row per recap, so each lands after the turn it summarizes.
|
|
103
|
+
id: `recap:${recap.generatedAt}`,
|
|
104
|
+
kind: RECAP_TIMELINE_KIND,
|
|
105
|
+
version: 1,
|
|
106
|
+
data,
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const ready = Promise.all([
|
|
112
|
+
store.load(),
|
|
113
|
+
mkdir(tempRoot, { recursive: true, mode: 0o700 }),
|
|
114
|
+
]).catch((error: unknown) => log("startup failed", errorMessage(error)));
|
|
115
|
+
|
|
116
|
+
const unsubscribers = [
|
|
117
|
+
server.on("agent.turn_started", async ({ agent }, context) => {
|
|
118
|
+
paseo = context.paseo;
|
|
119
|
+
await ready;
|
|
120
|
+
scheduler.turnStarted(agent);
|
|
121
|
+
}),
|
|
122
|
+
server.on("agent.turn_ended", async ({ agent, outcome, timeline }, context) => {
|
|
123
|
+
paseo = context.paseo;
|
|
124
|
+
await ready;
|
|
125
|
+
await scheduler.turnEnded(agent, outcome, timeline);
|
|
126
|
+
}),
|
|
127
|
+
server.on("agent.permission_requested", ({ agent, request }) => {
|
|
128
|
+
scheduler.permissionRequested(agent, request.id);
|
|
129
|
+
}),
|
|
130
|
+
server.on("agent.permission_resolved", async ({ agent, requestId }) => {
|
|
131
|
+
await ready;
|
|
132
|
+
await scheduler.permissionResolved(agent, requestId);
|
|
133
|
+
}),
|
|
134
|
+
server.on("agent.archived", async ({ agent }) => {
|
|
135
|
+
await ready;
|
|
136
|
+
await scheduler.archived(agent);
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
server.handle(recapGetRpc, async ({ agentId }, context) => {
|
|
141
|
+
paseo = context.paseo;
|
|
142
|
+
await ready;
|
|
143
|
+
return scheduler.view(agentId);
|
|
144
|
+
});
|
|
145
|
+
server.handle(recapListRpc, async (_input, context) => {
|
|
146
|
+
paseo = context.paseo;
|
|
147
|
+
await ready;
|
|
148
|
+
return { recaps: scheduler.list() };
|
|
149
|
+
});
|
|
150
|
+
server.handle(recapModelPlanRpc, async ({ generator }, context) => {
|
|
151
|
+
paseo = context.paseo;
|
|
152
|
+
return describeModelPlan(generator, await readGeneratorInputs(context.paseo));
|
|
153
|
+
});
|
|
154
|
+
server.handle(recapRegenerateRpc, async ({ agentId }, context) => {
|
|
155
|
+
paseo = context.paseo;
|
|
156
|
+
await ready;
|
|
157
|
+
try {
|
|
158
|
+
return await scheduler.regenerate(agentId);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
log(`manual recap failed for agent ${agentId}`, errorMessage(error));
|
|
161
|
+
return { ...scheduler.view(agentId), state: "error" as const, error: "Could not generate a recap." };
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return () => {
|
|
166
|
+
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
167
|
+
scheduler.dispose();
|
|
168
|
+
};
|
|
169
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paseo-recap",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Provider-agnostic agent recaps for Paseo, like Claude Code's session recap.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"paseo-plugin.json",
|
|
8
|
+
"OVERVIEW.md",
|
|
9
|
+
"index.client.ts",
|
|
10
|
+
"index.client.tsx",
|
|
11
|
+
"index.server.ts",
|
|
12
|
+
"index.server.tsx",
|
|
13
|
+
"client/",
|
|
14
|
+
"server/",
|
|
15
|
+
"shared/"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"test": "vitest run"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@getpaseo/client": "^0.10.3",
|
|
23
|
+
"@getpaseo/plugin": "0.10.3",
|
|
24
|
+
"@getpaseo/protocol": "^0.10.3",
|
|
25
|
+
"@tanstack/react-query": "^5.90.11",
|
|
26
|
+
"@types/node": "^22.20.5",
|
|
27
|
+
"@types/react": "~19.2.0",
|
|
28
|
+
"react": "19.1.0",
|
|
29
|
+
"react-native": "0.81.5",
|
|
30
|
+
"typescript": "^5.9.3",
|
|
31
|
+
"vitest": "^3.2.7",
|
|
32
|
+
"zod": "^4.4.3"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/kingsleydon/paseo-recap.git"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/kingsleydon/paseo-recap#readme",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/kingsleydon/paseo-recap/issues"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"paseo",
|
|
44
|
+
"paseo-plugin",
|
|
45
|
+
"recap"
|
|
46
|
+
]
|
|
47
|
+
}
|