paseo-recap 0.2.4 → 0.2.5
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/README.md +4 -9
- package/index.server.ts +2 -2
- package/package.json +1 -1
- package/server/history.ts +0 -33
- package/server/scheduler.ts +29 -55
package/README.md
CHANGED
|
@@ -126,15 +126,10 @@ paseo plugin logs paseo-recap
|
|
|
126
126
|
|
|
127
127
|
## Releasing
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
git tag recap-v0.2.4 && git push origin recap-v0.2.4
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
See the [repository README](../../README.md#releasing) for how the publish workflow works.
|
|
129
|
+
Title PRs `fix(recap): ...` or `feat(recap): ...`, then merge the release PR that release-please
|
|
130
|
+
opens. It bumps the version, updates [`CHANGELOG.md`](CHANGELOG.md), tags `recap-v<version>`,
|
|
131
|
+
creates the GitHub Release, and publishes to npm with [trusted publishing](https://docs.npmjs.com/trusted-publishers).
|
|
132
|
+
See the [repository README](../../README.md#releasing) for details.
|
|
138
133
|
|
|
139
134
|
## License
|
|
140
135
|
|
package/index.server.ts
CHANGED
|
@@ -119,10 +119,10 @@ export default function contribute(server: PluginServerContext) {
|
|
|
119
119
|
await ready;
|
|
120
120
|
scheduler.turnStarted(agent);
|
|
121
121
|
}),
|
|
122
|
-
server.on("agent.turn_ended", async ({ agent, outcome
|
|
122
|
+
server.on("agent.turn_ended", async ({ agent, outcome }, context) => {
|
|
123
123
|
paseo = context.paseo;
|
|
124
124
|
await ready;
|
|
125
|
-
await scheduler.turnEnded(agent, outcome
|
|
125
|
+
await scheduler.turnEnded(agent, outcome);
|
|
126
126
|
}),
|
|
127
127
|
server.on("agent.permission_requested", ({ agent, request }) => {
|
|
128
128
|
scheduler.permissionRequested(agent, request.id);
|
package/package.json
CHANGED
package/server/history.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { SETTING_RANGES } from "../shared/recap";
|
|
2
1
|
import type { AgentTimelineItem } from "./paseo-types";
|
|
3
2
|
|
|
4
|
-
/** Most exchanges a recap can read; the `historyExchanges` setting picks how many, up to this. */
|
|
5
|
-
export const HISTORY_EXCHANGES_LIMIT = SETTING_RANGES.historyExchanges.max;
|
|
6
|
-
/** Timeline items a recap reads; everything else is dropped before holding a timeline in memory. */
|
|
7
|
-
const RECAP_ITEM_TYPES: ReadonlySet<AgentTimelineItem["type"]> = new Set([
|
|
8
|
-
"user_message",
|
|
9
|
-
"assistant_message",
|
|
10
|
-
"error",
|
|
11
|
-
"compaction",
|
|
12
|
-
"todo",
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
3
|
const OMITTED_HISTORY = "[Earlier exchanges omitted]\n\n";
|
|
16
4
|
const EXCERPT_MARKER = "\n[... excerpted ...]\n";
|
|
17
5
|
const ERROR_MAX_CHARS = 300;
|
|
@@ -31,27 +19,6 @@ export function buildRecapHistory(
|
|
|
31
19
|
return formatHistory(collectExchanges(timeline).slice(-maxExchanges), maxHistoryBytes);
|
|
32
20
|
}
|
|
33
21
|
|
|
34
|
-
/**
|
|
35
|
-
* Keeps only what a recap can read: the text items of the last `HISTORY_EXCHANGES_LIMIT` exchanges
|
|
36
|
-
* plus the latest todo list. Turn-ended events carry the whole conversation, including tool output,
|
|
37
|
-
* which is too much to hold for every agent.
|
|
38
|
-
*/
|
|
39
|
-
export function trimForRecap(timeline: readonly AgentTimelineItem[]): AgentTimelineItem[] {
|
|
40
|
-
let seen = 0;
|
|
41
|
-
let start = 0;
|
|
42
|
-
for (let index = timeline.length - 1; index >= 0; index--) {
|
|
43
|
-
const item = timeline[index];
|
|
44
|
-
if (item?.type === "user_message" && item.text.trim() !== "" && ++seen === HISTORY_EXCHANGES_LIMIT) {
|
|
45
|
-
start = index;
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const kept = timeline.slice(start).filter((item) => RECAP_ITEM_TYPES.has(item.type));
|
|
50
|
-
if (kept.some((item) => item.type === "todo")) return kept;
|
|
51
|
-
const latestTodo = timeline.findLast((item) => item.type === "todo");
|
|
52
|
-
return latestTodo ? [latestTodo, ...kept] : kept;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
22
|
/** True while the provider is compacting context; a recap would describe a moving target. */
|
|
56
23
|
export function isCompacting(timeline: readonly AgentTimelineItem[]): boolean {
|
|
57
24
|
const last = timeline.findLast((item) => item.type === "compaction");
|
package/server/scheduler.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { PluginHookAgent, PluginTurnOutcome } from "@getpaseo/plugin/server
|
|
|
2
2
|
import type { RecapSettings, RecapState, RecapView, StoredRecap } from "../shared/recap";
|
|
3
3
|
import { errorMessage, NoGeneratorError, RecapSkippedError } from "./errors";
|
|
4
4
|
import type { GeneratedRecap } from "./generators";
|
|
5
|
-
import { buildRecapHistory, countUserTurns, isCompacting, latestActiveTask
|
|
5
|
+
import { buildRecapHistory, countUserTurns, isCompacting, latestActiveTask } from "./history";
|
|
6
6
|
import type { AgentTimelineItem } from "./paseo-types";
|
|
7
7
|
import { historyBudget, renderPrompt } from "./prompt";
|
|
8
8
|
|
|
@@ -47,7 +47,7 @@ export interface SchedulerDeps {
|
|
|
47
47
|
store: RecapStoreLike;
|
|
48
48
|
readSettings(): Promise<RecapSettings>;
|
|
49
49
|
generate(prompt: string, signal: AbortSignal, options: GenerateOptions): Promise<GeneratedRecap>;
|
|
50
|
-
/**
|
|
50
|
+
/** The conversation and live status, read right before each recap. */
|
|
51
51
|
fetchAgentContext(agentId: string): Promise<AgentContext>;
|
|
52
52
|
/** Shows a newly stored recap in the agent's conversation. */
|
|
53
53
|
publish(recap: StoredRecap): Promise<void>;
|
|
@@ -70,10 +70,6 @@ interface AgentEntry {
|
|
|
70
70
|
lastTurnCompleted: boolean;
|
|
71
71
|
/** Completed turns since the last stored recap; null until known (no recap observed yet). */
|
|
72
72
|
turnsSinceRecap: number | null;
|
|
73
|
-
/** User messages in the whole conversation (the kept timeline is trimmed). */
|
|
74
|
-
userTurns: number;
|
|
75
|
-
/** Trimmed to what a recap reads; see `trimForRecap`. */
|
|
76
|
-
timeline: readonly AgentTimelineItem[] | null;
|
|
77
73
|
pendingPermissions: Set<string>;
|
|
78
74
|
runningChildren: Set<string>;
|
|
79
75
|
timer: ReturnType<typeof setTimeout> | null;
|
|
@@ -114,16 +110,10 @@ export class RecapScheduler {
|
|
|
114
110
|
if (entry.parentAgentId) this.#entryById(entry.parentAgentId).runningChildren.add(entry.id);
|
|
115
111
|
}
|
|
116
112
|
|
|
117
|
-
async turnEnded(
|
|
118
|
-
agent: PluginHookAgent,
|
|
119
|
-
outcome: PluginTurnOutcome,
|
|
120
|
-
timeline: readonly AgentTimelineItem[],
|
|
121
|
-
): Promise<void> {
|
|
113
|
+
async turnEnded(agent: PluginHookAgent, outcome: PluginTurnOutcome): Promise<void> {
|
|
122
114
|
const entry = this.#entry(agent);
|
|
123
115
|
entry.running = false;
|
|
124
116
|
entry.runningSince = null;
|
|
125
|
-
entry.timeline = trimForRecap(timeline);
|
|
126
|
-
entry.userTurns = countUserTurns(timeline);
|
|
127
117
|
entry.lastTurnCompleted = outcome.kind === "completed";
|
|
128
118
|
if (entry.lastTurnCompleted && entry.turnsSinceRecap !== null) entry.turnsSinceRecap++;
|
|
129
119
|
if (entry.parentAgentId) {
|
|
@@ -178,30 +168,6 @@ export class RecapScheduler {
|
|
|
178
168
|
this.#clearTimer(entry);
|
|
179
169
|
entry.error = null;
|
|
180
170
|
entry.state = "generating";
|
|
181
|
-
let context: AgentContext;
|
|
182
|
-
try {
|
|
183
|
-
context = await this.#deps.fetchAgentContext(agentId);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
entry.state = "error";
|
|
186
|
-
entry.error = "Could not read the conversation.";
|
|
187
|
-
this.#deps.log(`could not fetch timeline for agent ${agentId}`, errorMessage(error));
|
|
188
|
-
return this.view(agentId);
|
|
189
|
-
}
|
|
190
|
-
entry.timeline = trimForRecap(context.timeline);
|
|
191
|
-
entry.userTurns = countUserTurns(context.timeline);
|
|
192
|
-
entry.title = context.title ?? entry.title;
|
|
193
|
-
entry.workspaceId = context.workspaceId ?? entry.workspaceId;
|
|
194
|
-
entry.provider = context.provider ?? entry.provider;
|
|
195
|
-
// Trust the daemon's live status over hook bookkeeping, which can miss a turn's end.
|
|
196
|
-
if (context.running) {
|
|
197
|
-
entry.state = "idle";
|
|
198
|
-
entry.error = "The agent is running. Try again when it is idle.";
|
|
199
|
-
return this.view(agentId);
|
|
200
|
-
}
|
|
201
|
-
if (entry.running) {
|
|
202
|
-
entry.running = false;
|
|
203
|
-
entry.runningSince = null;
|
|
204
|
-
}
|
|
205
171
|
await this.#run(entry, "manual");
|
|
206
172
|
return this.view(agentId);
|
|
207
173
|
}
|
|
@@ -284,9 +250,7 @@ export class RecapScheduler {
|
|
|
284
250
|
if (entry.running || !entry.lastTurnCompleted || entry.inFlight) return false;
|
|
285
251
|
if (entry.pendingPermissions.size > 0) return false;
|
|
286
252
|
if (settings.waitForSubagents && this.#hasBlockingChild(entry)) return false;
|
|
287
|
-
if (entry.failures >= MAX_CONSECUTIVE_FAILURES
|
|
288
|
-
if (isCompacting(entry.timeline)) return false;
|
|
289
|
-
if (entry.userTurns < settings.minTurns) return false;
|
|
253
|
+
if (entry.failures >= MAX_CONSECUTIVE_FAILURES) return false;
|
|
290
254
|
// Without an observed recap (fresh agent or daemon restart), recap the next completed turn.
|
|
291
255
|
return entry.turnsSinceRecap === null || entry.turnsSinceRecap >= settings.turnsBetweenRecaps;
|
|
292
256
|
}
|
|
@@ -302,20 +266,32 @@ export class RecapScheduler {
|
|
|
302
266
|
|
|
303
267
|
async #generate(entry: AgentEntry, trigger: Trigger, abort: AbortController): Promise<void> {
|
|
304
268
|
const revision = entry.revision;
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
if (abort.signal.aborted || entry.revision !== revision || this.#disposed) return;
|
|
308
|
-
const timeline = entry.timeline ?? [];
|
|
309
|
-
const context = { goal: entry.title, activeTask: latestActiveTask(timeline) };
|
|
310
|
-
const history = buildRecapHistory(timeline, historyBudget(context), historyExchanges);
|
|
311
|
-
if (history === "") {
|
|
269
|
+
const manual = trigger === "manual";
|
|
270
|
+
const skip = (error: string | null) => {
|
|
312
271
|
entry.state = "idle";
|
|
313
|
-
entry.error =
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
entry.state = "generating";
|
|
317
|
-
entry.error = null;
|
|
272
|
+
entry.error = manual ? error : null;
|
|
273
|
+
};
|
|
318
274
|
try {
|
|
275
|
+
const [settings, agent] = await Promise.all([
|
|
276
|
+
this.#deps.readSettings(),
|
|
277
|
+
this.#deps.fetchAgentContext(entry.id),
|
|
278
|
+
]);
|
|
279
|
+
// A turn may have started meanwhile; it has already reset this entry.
|
|
280
|
+
if (abort.signal.aborted || entry.revision !== revision || this.#disposed) return;
|
|
281
|
+
entry.title = agent.title ?? entry.title;
|
|
282
|
+
entry.workspaceId = agent.workspaceId ?? entry.workspaceId;
|
|
283
|
+
entry.provider = agent.provider ?? entry.provider;
|
|
284
|
+
// Trust the daemon's live status over hook bookkeeping, which can miss a turn's end.
|
|
285
|
+
if (agent.running) return skip("The agent is running. Try again when it is idle.");
|
|
286
|
+
entry.running = false;
|
|
287
|
+
entry.runningSince = null;
|
|
288
|
+
const userTurns = countUserTurns(agent.timeline);
|
|
289
|
+
if (!manual && (isCompacting(agent.timeline) || userTurns < settings.minTurns)) return skip(null);
|
|
290
|
+
const context = { goal: entry.title, activeTask: latestActiveTask(agent.timeline) };
|
|
291
|
+
const history = buildRecapHistory(agent.timeline, historyBudget(context), settings.historyExchanges);
|
|
292
|
+
if (history === "") return skip("There is no conversation to recap yet.");
|
|
293
|
+
entry.state = "generating";
|
|
294
|
+
entry.error = null;
|
|
319
295
|
const generated = await this.#deps.generate(renderPrompt(history, context), abort.signal, {
|
|
320
296
|
agentProvider: entry.provider,
|
|
321
297
|
trigger,
|
|
@@ -328,7 +304,7 @@ export class RecapScheduler {
|
|
|
328
304
|
nextAction: generated.nextAction,
|
|
329
305
|
generatedAt: new Date().toISOString(),
|
|
330
306
|
revision,
|
|
331
|
-
turnCount:
|
|
307
|
+
turnCount: userTurns,
|
|
332
308
|
stale: false,
|
|
333
309
|
trigger,
|
|
334
310
|
generator: { provider: generated.provider, model: generated.model },
|
|
@@ -413,8 +389,6 @@ export class RecapScheduler {
|
|
|
413
389
|
runningSince: null,
|
|
414
390
|
lastTurnCompleted: false,
|
|
415
391
|
turnsSinceRecap: null,
|
|
416
|
-
userTurns: 0,
|
|
417
|
-
timeline: null,
|
|
418
392
|
pendingPermissions: new Set(),
|
|
419
393
|
runningChildren: new Set(),
|
|
420
394
|
timer: null,
|