char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somadd skills extension for loading skillsa4e772a

main
5.0 KiB102 linesraw
1import { assert, assertEquals, assertStringIncludes } from "@std/assert";
2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context";
3import { getCurrentSystemPrompt } from "@earendil-works/pi-ai/utils/transcript";
4import { fauxAssistantMessage, fauxToolCall } from "@earendil-works/pi-ai/providers/faux";
5import { rootedEnvironment } from "@berry/api/testing.ts";
6import { tempDir } from "@berry/util";
7import { skillsExtension } from "../extensions/skills/mod.ts";
8import { hostEnvironment, writeSkill } from "../extensions/skills/testing.ts";
9import { lastToolResult, setup, toolsOffered, turn } from "./fixture.ts";
10
11Deno.test("skill snapshots reach the next request and survive compaction, reload, and historical forks", async () => {
12  await using root = await tempDir();
13  const env = rootedEnvironment(root.path);
14  const skills = skillsExtension(hostEnvironment(root.path));
15  const body =
16    "Review the primary evidence verbatim: ζ  exact spacing.\nNever skip the release checklist.\n";
17  await writeSkill(env, "/home/.agents/skills", "release", body);
18  await using harness = await setup({
19    open: (name, cwd) =>
20      Promise.resolve(Object.assign(rootedEnvironment(root.path, { cwd: cwd ?? "/" }), { name })),
21    close: () => Promise.resolve(),
22  });
23  const { berry, model, faux } = harness;
24  await berry.install(skills);
25  const tid = await berry.create({ extensions: { environment: { cwd: "/" } }, model });
26  const conversation = (await berry.conversation(tid))!;
27  const [before, after] = await turn(harness, tid, [
28    fauxAssistantMessage(fauxToolCall("load_skill", { name: "release" }), {
29      stopReason: "toolUse",
30    }),
31  ]);
32  assert(toolsOffered(before).includes("load_skill"));
33  assert(!getCurrentSystemPrompt(before).includes(body));
34  assertStringIncludes(getCurrentSystemPrompt(after), body);
35  assert(!lastToolResult(after).text.includes(body));
36  const loadedAt =
37    (await conversation.entries({ order: "descending" }, 1, undefined, context)).items[0].id;
38
39  await writeSkill(env, "/home/.agents/skills", "release", "Changed on disk.");
40  faux.setResponses([fauxAssistantMessage("done")]);
41  await (await conversation.submit({ type: "input", content: "x".repeat(100_000) }, context)).wait(
42    context,
43  );
44  await conversation.waitForIdle(context);
45  faux.setResponses([fauxAssistantMessage("A deliberately lossy summary.")]);
46  await berry.harness.waitForTask(await conversation.compact(undefined, context), context);
47  await berry.install(skills);
48  const [compacted] = await turn(harness, tid, []);
49  assertStringIncludes(getCurrentSystemPrompt(compacted), body);
50  assert(!getCurrentSystemPrompt(compacted).includes("Changed on disk."));
51
52  const calls = faux.state.callCount;
53  await berry.command(tid, "unskill", "release");
54  assertEquals(faux.state.callCount, calls);
55  const [unloaded] = await turn(harness, tid, []);
56  assert(!getCurrentSystemPrompt(unloaded).includes(body));
57
58  const fork = await conversation.fork(loadedAt, { ownership: { kind: "ownerless" } }, context);
59  const [forked] = await turn(harness, await berry.tidOf(fork.id), []);
60  assertStringIncludes(getCurrentSystemPrompt(forked), body);
61  await berry.branch(tid, loadedAt);
62  const [rewound] = await turn(harness, tid, []);
63  assertStringIncludes(getCurrentSystemPrompt(rewound), body);
64});
65
66Deno.test("subagents discover environment-local skills without inheriting their parent's active instructions", async () => {
67  await using root = await tempDir();
68  const env = rootedEnvironment(root.path);
69  const skills = skillsExtension(hostEnvironment(root.path));
70  const body = "Parent-only instructions: carefully audit the publication process.";
71  await writeSkill(env, "/home/.agents/skills", "release", body);
72  await using harness = await setup({
73    open: (name, cwd) =>
74      Promise.resolve(Object.assign(rootedEnvironment(root.path, { cwd: cwd ?? "/" }), { name })),
75    close: () => Promise.resolve(),
76  });
77  const { berry, faux, model } = harness;
78  await berry.install(skills);
79  const tid = await berry.create({
80    extensions: { environment: { cwd: "/" }, subagent: {} },
81    model,
82  });
83  await berry.command(tid, "skill", "release");
84  let childPrompt: string | undefined;
85  faux.setResponses(Array.from({ length: 4 }, () => (request) => {
86    const last = request.messages.findLast((message) => message.role !== "system");
87    if (last?.role === "user" && last.content === "go") {
88      assertStringIncludes(getCurrentSystemPrompt(request.messages), body);
89      return fauxAssistantMessage(fauxToolCall("subagent", { task: "A separate check.", model }), {
90        stopReason: "toolUse",
91      });
92    }
93    if (last?.role === "user") childPrompt = getCurrentSystemPrompt(request.messages);
94    return fauxAssistantMessage("done");
95  }));
96  const conversation = (await berry.conversation(tid))!;
97  await (await conversation.submit({ type: "input", content: "go" }, context)).wait(context);
98  await conversation.waitForIdle(context);
99  assert(childPrompt !== undefined);
100  assertStringIncludes(childPrompt, '"name":"release"');
101  assert(!childPrompt.includes(body));
102});