char-slop/berry

multipurpose self-modifiable agentic harness

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

Charlotte Somcut a bunch of code volumecb11725

main
2.0 KiB48 linesraw
1import { assert, assertEquals, assertStringIncludes } from "@std/assert";
2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context";
3import { fauxAssistantMessage, fauxToolCall } from "@earendil-works/pi-ai/providers/faux";
4import { LiveDoc } from "@earendil-works/pi-durable";
5import code from "../extensions/code/mod.ts";
6import { lastToolResult, setup, turn } from "./fixture.ts";
7import { tempDir } from "@berry/util";
8
9Deno.test("direct bash calls preserve live ANSI output despite harness stream sanitization", async () => {
10  await using rootDir = await tempDir({ prefix: "bash-stream-test-" });
11  const root = rootDir.path;
12  await using harness = await setup();
13  let running: ReturnType<typeof turn> | undefined;
14  try {
15    await harness.berry.install(code);
16    const tid = await harness.berry.create({
17      extensions: { environment: { cwd: root }, code: {} },
18      model: harness.model,
19    });
20    const conversation = (await harness.berry.conversation(tid))!;
21    running = turn(harness, tid, [
22      fauxAssistantMessage(
23        fauxToolCall("bash", {
24          command:
25            "printf '\\033[31mred'; while [ ! -f release ]; do sleep 0.01; done; printf '\\033[0m plain\\n'",
26          timeout: 5,
27        }),
28        { stopReason: "toolUse" },
29      ),
30    ]);
31    let slot;
32    for (let i = 0; i < 200; i++) {
33      slot = (await harness.berry.harness.snapshot(LiveDoc, conversation.id, context))?.tools?.[0];
34      if ((slot?.details as { rawOutput?: string } | undefined)?.rawOutput === "\x1b[31mred") break;
35      await new Promise((resolve) => setTimeout(resolve, 10));
36    }
37    assert(slot);
38    assertEquals(slot.status, "running");
39    assertEquals((slot.details as { rawOutput: string }).rawOutput, "\x1b[31mred");
40    assertEquals(slot.output, "[31mred");
41    await Deno.writeTextFile(`${root}/release`, "");
42    const seen = await running;
43    assertStringIncludes(lastToolResult(seen[1]).text, "\x1b[31mred\x1b[0m plain");
44  } finally {
45    await Deno.writeTextFile(`${root}/release`, "");
46    await running;
47  }
48});