char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somadd a /compact command to misc2c01ad9

main
1.7 KiB39 linesraw
1import { assertEquals, assertStringIncludes } from "@std/assert";
2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context";
3import type { Message } from "@earendil-works/pi-ai";
4import { fauxAssistantMessage } from "@earendil-works/pi-ai/providers/faux";
5import { until } from "@berry/util";
6import misc from "../extensions/misc/mod.ts";
7import { setup, turn } from "./fixture.ts";
8
9const textOf = (messages: readonly Message[]) =>
10  messages.flatMap((message) =>
11    typeof message.content === "string"
12      ? [message.content]
13      : message.content.flatMap((block) => block.type === "text" ? [block.text] : [])
14  ).join("\n");
15
16Deno.test("/compact compacts the conversation, guided by its arguments", async () => {
17  await using harness = await setup();
18  const { berry, faux, model } = harness;
19  await berry.install(misc);
20  const tid = await berry.create({ extensions: {}, model });
21  const conversation = (await berry.conversation(tid))!;
22  await turn(harness, tid, []);
23  faux.setResponses([fauxAssistantMessage("done")]);
24  await (await conversation.submit({ type: "input", content: "x".repeat(100_000) }, context))
25    .wait(context);
26  await conversation.waitForIdle(context);
27
28  let summarized: readonly Message[] = [];
29  faux.setResponses([(request) => {
30    summarized = request.messages;
31    return fauxAssistantMessage("A summary");
32  }]);
33  assertEquals(await berry.command(tid, "compact", "keep the long input"), "Compacting context…");
34  await until(async () =>
35    (await conversation.entries({ order: "ascending" }, 100, undefined, context)).items
36      .some((entry) => entry.kind === "pi.compaction")
37  );
38  assertStringIncludes(textOf(summarized), "Additional focus: keep the long input");
39});